我有一个大的 numpy 数组 (dtype=int
) 和一组我想在该数组中找到的数字,例如,
import numpy as np
values = np.array([1, 2, 3, 1, 2, 4, 5, 6, 3, 2, 1])
searchvals = [3, 1]
# result = [0, 2, 3, 8, 10]
result
数组不需要排序。
速度是个问题,因为 values
和 searchvals
都可以很大,
for searchval in searchvals:
np.where(values == searchval)[0]
不会剪掉它。
有什么提示吗?
最佳答案
这够快吗?
>>> np.where(np.in1d(values, searchvals))
(array([ 0, 2, 3, 8, 10]),)
关于python - Numpy 整数数组 : Find indices of multiple target ints,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38266259/