-1

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!

Evey
  • 11
  • 2

1 Answers1

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