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!
Asked
Active
Viewed 65 times
-1

Evey
- 11
- 2
-
`arr.index(a)` should work fine. – Sid May 22 '21 at 11:30
-
1`'numpy.ndarray' object has no attribute 'index'` this is what I get – Evey May 22 '21 at 11:36
1 Answers
1
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)

aoxmxoa
- 31
- 3