[Python_Error] TypeError: slice indices must be integers or None or have an __index__ method


[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..


원문링크 : [Python_Error] TypeError: slice indices must be integers or None or have an __index__ method