[英]Most efficient way to test whether each element from one array exists in a another array, using numpy
I would like to know the most efficient way of determining whether elements from a 1-d numpy array exist in another array. 我想知道确定一维numpy数组中的元素是否存在于另一个数组中的最有效方法。
Specifically, I have two numpy 1-d arrays. 具体来说,我有两个numpy 1-d数组。 The first is an unsorted array of integers.
第一个是未排序的整数数组。 The second is a sorted array of target values.
第二个是目标值的排序数组。
Sample input: 输入样例:
[45982, 124, 12, 1092, 45982, 1, 985, 299, 10092] # array 1
[1, 12, 299] # array 2
Expected output (ie array 1 elements in array 2): 预期输出(即数组2中的数组1元素):
[False, False, True, False, False, True, False, True, False]
The actual arrays will be much longer: array 1 is likely to contain >5,000,000 elements, array 2 is likely to contain from 500,000 to 1,000,000 elements. 实际的数组将更长:数组1可能包含> 5,000,000个元素,数组2可能包含500,000至1,000,000个元素。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.