考虑到以下代码:
>>> initial_array = np.vstack(([0, 1, 2, 3, 4, 11, 6, 7, 8, 9], [1, 11, 12, 13, 14, 15, 16, 17, 18, 19])).T
>>> initial_array
array([[ 0, 1],
[ 1, 11],
[ 2, 12],
[ 3, 13],
[ 4, 14],
[11, 15],
[ 6, 16],
[ 7, 17],
[ 8, 18],
[ 9, 19]])
>>> test = np.vstack(([0, 1, 2, 67, 4, 5], [10, 11, 67, 13, 14, 67])).T
>>> test
array([[ 0, 10],
[ 1, 11],
[ 2, 67],
[67, 13],
[ 4, 14],
[ 5, 67]])
有没有一种比较initial_array
w.r.ttest
的每一行的方法来得到如下掩码?你知道吗
[False, True, False, False, True, False, False, False, False, False]
其思想是要知道initial_array
的哪些行(对)包含在test
中。你知道吗
提前谢谢。你知道吗
您可以使用广播在两个数组中的每个数组中的所有对之间进行比较,然后使用
np.any
和np.all
将结果合并到所需的一维数组中作为结果:您可以尝试利用unique()函数。你知道吗
代码:
稍微简单一点的解决方案是使用合并数组上的unique()为每个唯一的行分配一个唯一的整数。接下来,使用numpy中可用的1D set操作(function in1d())完成比较
此解决方案的缺点是执行两种排序(unique()和in1d())。你知道吗
这里有一种方法:
相关问题 更多 >
编程相关推荐