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

전체 글98

[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: ufunc 'true_divide' not supported for the input types, and the inputs could not be safely coerced to any supported types according to the casting rule ''safe'' 본 포스팅은 업무 중 발생했던 오류들을 예시를 통해 어떻게 해결을 했는지 적을 예정이다. TypeError: ufunc 'true_divide' not supported for the input types, and the inputs could not be safely coerced to any supported types according to the casting rule ''safe'' 이 오류는 숫자와 np.array로 싸인 string 변수를 나눌 때 발생했던 오류이다. [예시] import numpy as np number_1 = np.array([3,6,9]) # float array number_2 = np.array(str(3)) # string number_1/number_2 """ T.. 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.
[Python_Error] TypeError: only integer scalar arrays can be converted to a scalar index 본 포스팅은 업무 중 발생했던 오류들을 예시를 통해 어떻게 해결을 했는지 적을 예정이다. TypeError: only integer scalar arrays can be converted to a scalar index list index에 scalar 가 아닌 np.array가 들어갔을 때 발생하는 오류이다. [예시] import numpy as np rand_cube_3D = np.random.randint(0,10,size=[5,5,5]) print(rand_cube_3D) """ array([[[3, 1, 4, 8, 9], [7, 1, 2, 8, 3], [4, 9, 0, 6, 9], [8, 9, 9, 4, 0], [5, 0, 5, 8, 1]], [[9, 4, 2, 9, 2], [6, 7, 6, 8.. 2022. 9. 29.
[Python] Image filtering - 영상처리에 대해 오늘은 영상처리의 기본 개념 및 필터에 대해 포스팅하겠다. Scipy에서 제공하는 라이브러를 사용하여 구현하겠다. Filter • Heart of image enhancement • Remove noise or undesirable impurities • The first derivative and second derivative filters are used to determine edges in an image • Linear filter – Mean, Laplacian and Laplacian of Gaussian • Non-linear filter – median, maximum, minimum, Sobel, Prewitt, Canny filter Image Enhancement • Be acco.. 2022. 9. 26.
[Python] np.where() - 조건 두 개 사용하는 법 본 포스팅은 넘파이 어레이의 특정 조건에 부합하는 인덱스를 찾아주는 np.where()에 대해 정리할 예정이다. 다만 이전에 포스팅한 내용은 조건 하나의 경우지만 이번에는 두 개의 조건에 동시에 부합하는 경우 어떻게 사용이 되는지 포스팅하겠다. np.where() - AND 연산 (&) 우선 두개의 조건을 둘 다 부합할 경우 즉, AND 논리의 경우 어떻게 np.where()을 사용해야 하는지 예시를 통해 정리하겠다. [np.where((조건_1)&(조건_2)] import numpy as np nums = np.array([1,2,3,4,5,6,7,8,9,10]) np.where(nums > 3) # (array([3, 4, 5, 6, 7, 8, 9], dtype=int64),) np.where(num.. 2022. 9. 26.
728x90
반응형