-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!

2
  • arr.index(a) should work fine. Commented May 22, 2021 at 11:30
  • 1
    'numpy.ndarray' object has no attribute 'index' this is what I get Commented May 22, 2021 at 11:36

1 Answer 1

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)
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.