有没有可能用numpy找出数组中元素的位置?

is there a posibillity to find out the position on an element in an array with numpy?

如果我有一个像 [1, 7, 10, 5, 2, 9, 8] 这样的 numpy 数组,是否有可能找出这个数组中哪个位置是一个特殊元素,例如 5? 感谢您的帮助!

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

虽然还有很多其他方法,但这可能会奏效,但这个方法很容易理解

i= numpy.where(vector == 5)

通过 numpy 库,你可以在没有循环的情况下做到这一点。

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

它returns指定值的第一次出现。