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

Anand S Kumar
  • 88,551
  • 18
  • 188
  • 176
user3737702
  • 591
  • 1
  • 10
  • 17

1 Answers1

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),)
Anand S Kumar
  • 88,551
  • 18
  • 188
  • 176