0

If i've got an numpy array like for example [1, 7, 10, 5, 2, 9, 8], is there a posibillity to find out on which position in this array is one special Element, for example the 5? Thanks for your help!

AufsMaulwurf
  • 41
  • 1
  • 6
  • Does this answer your question? [Is there a NumPy function to return the first index of something in an array?](https://stackoverflow.com/questions/432112/is-there-a-numpy-function-to-return-the-first-index-of-something-in-an-array) – Mihai Alexandru-Ionut Nov 29 '20 at 13:13

3 Answers3

1
flag=0
demo = [1, 7, 10, 5, 2, 9, 8]
for x in demo:
    if x==5:
        print('Position',flag+1)
    flag+=1 

This might just work although there are many other ways but this one simple to digest

Brainiac
  • 159
  • 8
0
i= numpy.where(vector == 5)

By numpy library you can do this without loop.

-1
x=[1, 7, 10, 5, 2, 9, 8]
print(x.index(5))

It returns the first occurrence of the specified value.