I have a list a=[1,2,3,4], and an array arr=np.array([[1,1,1,1],[1,2,3,4],[2,2,2,2]). I want to compare a and arr to get the index of a in arr. How can I do that? I wish to get the output in integer (in this case is 1) because I need the index to proceed with other processes. Thanks in advance!
1 Answer
One way to get the index is to convert the numpy array to a python nested list and just use the index method() on the converted list
(By the way you are missing a closing "]" in your declaration of arr)
import numpy as np
a = [1, 2, 3, 4]
arr=np.array([[1,1,1,1],[1,2,3,4],[2,2,2,2]])
lst = arr.tolist()
idx = lst.index(a)
arr.index(a)should work fine.'numpy.ndarray' object has no attribute 'index'this is what I get