Numpy:快速找到第一个价值指数 [英] Numpy: find first index of value fast

查看:153
本文介绍了Numpy:快速找到第一个价值指数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在Numpy数组中找到第一次出现的索引号?
速度对我很重要。我对以下答案不感兴趣,因为它们扫描整个数组,并且在发现第一次出现时不停止:

  itemindex = numpy.where(array == item)[0] [0] 
nonzero(array == item)[0] [0]
$ b $是一个函数返回的索引的东西b

注意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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆