Numpy:快速找到第一个价值指数 [英] Numpy: find first index of value fast
问题描述
如何在Numpy数组中找到第一次出现的索引号?
速度对我很重要。我对以下答案不感兴趣,因为它们扫描整个数组,并且在发现第一次出现时不停止:
itemindex = numpy.where(array == item)[0] [0]
$ p $注意1:这个问题的答案没有一个是相关的 $ b $是一个函数返回的索引的东西b
nonzero(array == item)[0] [0]
注意2:使用C编译的方法比Python循环更受欢迎。
解决方案是为Numpy 2.0.0计划的功能请求: https://github.com/numpy/ numpy / issues / 2269
How can I find the index of the first occurrence of a number in a Numpy array? Speed is important to me. I am not interested in the following answers because they scan the whole array and don't stop when they find the first occurrence:
itemindex = numpy.where(array==item)[0][0] nonzero(array == item)[0][0]
Note 1: none of the answers from that question seem relevant Is there a Numpy function to return the first index of something in an array?
Note 2: using a C-compiled method is preferred to a Python loop.
解决方案There is a feature request for this scheduled for Numpy 2.0.0: https://github.com/numpy/numpy/issues/2269
这篇关于Numpy:快速找到第一个价值指数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!