본문 바로가기
  • Hello_
728x90
반응형

Python Error3

[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_Error] TypeError: slice indices must be integers or None or have an __index__ method 본 포스팅은 업무 중 발생했던 오류들을 예시를 통해 어떻게 해결을 했는지 적을 예정이다. TypeError: slice indices must be integers or None or have an __index__ method 해당 오류는 list를 슬라이싱 할 때 int의 조합이 아니라 실수의 조합으로 입력이 되면 발생하는 오류이다. 필자는 //을 사용하여 입력을 정수로 만들고 슬라이싱을 진행하고자 했으나 float로 출력이 되어서 발생했던 오류이다. [예시] import numpy as np rand = [77, 84, 39, 42, 64] print(rand) # [77, 84, 39, 42, 64] ori_idx = np.array([3.,9.]) half_idx = ori_idx // 2 pr.. 2022. 9. 29.
[Python_Error] TypeError: unsupported operand type(s) for -: 'int' and 'list' 본 포스팅은 업무 중 발생했던 오류들을 예시를 통해 어떻게 해결을 했는지 적을 예정이다. TypeError: unsupported operand type(s) for -: 'int' and 'list' 본 오류는 array 내에 scalar 값이 아닌 list가 들어가서 발생한 오류이다. [예시] import numpy as np rand_cube_3D = np.random.randint(0,100,size=[3,3,3]) print(rand_cube_3D) """ array([[[87, 58, 63], [ 3, 44, 32], [81, 11, 80]], [[20, 84, 77], [56, 8, 32], [38, 99, 61]], [[71, 83, 58], [85, 29, 65], [67, 33, 70].. 2022. 9. 29.
728x90
반응형