[英]Pandas python what to solve in IndexError
I receive the following error when I try to count occurences of each element in ListA
from ListB
.当我尝试从
ListB
ListA
每个元素的出现次数时,我收到以下错误。
ListA = [*range(0,10000000, 1)] ListB = [5,4,778,577,369,1147, 7851387,115547,...] count_arr = np.bincount(ListB) Number_of_counts = [count_arr[x] for x in ListA]
I get the following error with which I do not know what is wrong since ListA
is just a range of numbers.我收到以下错误,我不知道出了什么问题,因为
ListA
只是一个数字范围。
IndexError Traceback (most recent call last) <ipython-input-18-2f121c135a65> in <module> 1 count_arr = np.bincount(ListA) ----> 2 Number_of_counts = [count_arr[x] for x in ListB] <ipython-input-18-2f121c135a65> in <listcomp>(.0) 1 count_arr = np.bincount(ListB) ----> 2 Number_of_counts = [count_arr[x] for x in ListA] IndexError: index 1715766 is out of bounds for axis 0 with size 1715766
ListA's
length is bigger than count_arr
's length. ListA's
长度大于count_arr
的长度。 Therefore, when you loop through count_arr
using ListA
's indexes, you get and error.因此,当您使用
ListA
的索引遍历count_arr
时,您会得到错误。 Their length should be the same它们的长度应该相同
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.