-1

If let's set a=array([1,4,5,57,45,34]) so how do we get the index of one element? say 5 etc.

I know how to get the index in a list, using list.index(ele). But how about an array? Is there any similar function, .index definitely not work as I have tried this? Or we have to develop function by our own?

There are other similar questions using perl, C,etc, but I have not found one using python in this community.

0

1 Answer 1

3

If you want all indices for element 5, you can use numpy.where , Example -

In [1]: from numpy import array

In [2]: a=array([1,4,5,57,45,34])

In [3]: from numpy import where

In [4]: where(a==5)
Out[4]: (array([2], dtype=int64),)
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.