python - 检查 NumPy 数组中是否存在值的最有效方法是什么?

标签 python performance numpy

我有一个非常大的 NumPy 数组

1 40 3
4 50 4
5 60 7
5 49 6
6 70 8
8 80 9
8 72 1
9 90 7
.... 

我想检查数组的第一列中是否存在值。我有很多本土方法(例如遍历每一行并检查),但考虑到数组的大小,我想找到最有效的方法。

谢谢!

最佳答案

怎么样

if value in my_array[:, col_num]:
    do_whatever

编辑:我认为 __contains__ 的实现方式与@detly 的版本相同

关于python - 检查 NumPy 数组中是否存在值的最有效方法是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7088625/

相关文章:

python - Numpy:通过分箱从关联中查找不同值的计数

python - 类型错误 : 'bool' object is not subscriptable Python 3

python - Bash 或 Python 倒退?

python - 如何在Python中获取数学函数作为用户的输入并在循环中使用它

python - 评估函数不同参数的性能

performance - 并行成本和并行工作有什么区别?

python - Python 中的语法 (.T)

Python Pandas - 根据列表删除多个值

python - tensorflow 占位符 - 理解 `shape=[None,`

java - jni 函数调用一些 gdb 不知道的 libc 函数