Is there a way to find an index of an array inside another array without converting them to list or using a for loop?
I have a huge data set and I don't want to add another loop and make it slower
arr = np.array([[11, 19, 18], [14, 15, 11], [19, 21, 46], [29, 21, 19]])
find_this_array = np.array([14, 15, 11])
# I want to avoid this
a = arr.tolist()
val = find_this_array.tolist()
a.index(val)
output:
1
CodePudding user response:
You can try this:
np.where((arr == find_this_array).all(axis=1))[0][0]
output:
1
You can find more details about Numpy where
from their documentation:
https://numpy.org/doc/stable/reference/generated/numpy.where.html