728x90 반응형 np.expand_dims2 [Python_Error] ValueError: all the input arrays must have same number of dimensions (np.concatenate 오류) 본 포스팅은 업무 중 발생했던 오류들을 예시를 통해 어떻게 해결을 하는지 작성했다. ValueError: all the input arrays must have same number of dimensions, but the array at index 0 has 3 dimension(s) and the array at index 1 has 4 dimension(s) 해당 오류는 np.concatenate()을 사용할때 발생했던 오류이며, 특히 3차원 이상의 어레이들을 concat할때 많이 보이는 오류이다. 특히 2차원 이미지에 배치, 채널이 포함된 데이터의 경우 자주 발생했다. [예시_1] 다음과 같이 np.concatenate는 사용할 때 특정 축을 기준으로 결합이 되기 때문에 axis 인자에 입력한 특.. 2022. 10. 4. [Python] np.newaxis, np.expand_dims(), np.squeeze() - 차원 및 축 조절하기 오늘은 numpy로 차원을 늘리고 줄이는 방법에 대해 포스팅해보겠다. np.newaxis() np.newaxis()는 함수명 그대로 넘파이 어레이의 차원의 수를 늘려주는 역할을 한다. 차원을 늘리고자 하는 인덱스에 np.newaxis를 포함하면 해당하는 차원이 늘어난다. import numpy as np example = np.arange(10) print(example.shape) # (10,) exam_1 = example[np.newaxis,:] exam_2 = example[:,np.newaxis] print(exam_1.shape, exam_2.shape) # (1, 10) (10, 1) 또한 한 차원이 아니라 여러 차원을 한 번에 늘릴 수도 있다. exam_3 = example[np.newax.. 2022. 9. 12. 이전 1 다음 728x90 반응형