I receive the following error when I try to count occurences of each element in ListA
from ListB
.
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.
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. Therefore, when you loop through count_arr
using ListA
's indexes, you get and error. Their length should be the same
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.