简体   繁体   English

使用numpy测试一个数组中的每个元素是否存在于另一个数组中的最有效方法

[英]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个元素。

maybe np.in1d : 也许np.in1d

>>> xs = np.array([45982, 124, 12, 1092, 45982, 1, 985, 299, 10092])
>>> ys = np.array([1, 12, 299])
>>> np.in1d(xs, ys)
array([False, False,  True, False, False,  True, False,  True, False], dtype=bool)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 使用python测试一个1-d数组中的每个元素是否存在于另一个2-d数组的相应行中的最有效方法 - Most efficient way to test whether each element from one 1-d array exists in corresponding row of another 2-d array, using python 对 Numpy 数组的每个元素应用操作的最有效方法 - Most efficient way to apply operation on each element of Numpy array 在另一个数组中找到一个 numpy 数组的行列的最有效方法是什么? - What is the most efficient way of finding the ranks of one numpy array in another? 检查 NumPy 数组中是否存在值的最有效方法是什么? - What is the most efficient way to check if a value exists in a NumPy array? 从一个numpy数组中删除元素的有效方法 - Efficient way to delete elements in one numpy array from another 比较2D numpy数组中的每个元素与其8个相邻元素的最有效方法 - Most efficient way of comparing each element in a 2D numpy array to its 8 neighbours 通过x步滚动numpy数组中每一列的最有效方法 - Most efficient way to roll each column in a numpy array by x steps 对 numpy 数组的每一列应用线性变换的最有效方法 - Most efficient way to apply linear transformations to each column of a numpy array 从另一个二维索引数组重新排列二维 numpy 数组的最有效方法 - Most efficient way to rearrange 2D numpy array from another 2D index array 高效的实施检查:对于数组中的每个元素,检查其是否存在于另一个数组中 - Efficient implementation to check: for each element in array check if it exists in another array
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM