Numpy equivalent of list.index

前端 未结 6 2254
粉色の甜心
粉色の甜心 2021-02-12 11:48

In a low-level function that is called many times, I need to do the equivalent of python\'s list.index, but with a numpy array. The function needs to return when it finds the f

6条回答
  •  心在旅途
    2021-02-12 12:09

    The only time I've had this problem, it was sufficient to cast the numpy array as a list:

    a = numpy.arange(3)
    print(list(a).index(2))
    
    >>> 2
    

提交回复
热议问题