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!
Asked
Active
Viewed 45 times
0
-
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 Answers
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
-1
x=[1, 7, 10, 5, 2, 9, 8]
print(x.index(5))
It returns the first occurrence of the specified value.

Pradyumna C
- 11
- 1
-
Question was asking for a method using `numpy`, not standard library. – Andre.IDK Nov 29 '20 at 16:45