【发布时间】:2021-09-13 20:55:13
【问题描述】:
我有一个数组 group,它是 Nx2:
array([[ 1, 6],
[ 1, 0],
[ 2, 1],
...,
[40196, 40197],
[40196, 40198],
[40196, 40199]], dtype=uint32)
还有另一个数组selection,即(M,):
array([3216, 3217, 3218, ..., 8039])
我想创建一个包含group 的所有行的新数组,其中两个元素都在selection 中。我就是这样做的:
np.array([(i,j) for (i,j) in group if i in selection and j in selection])
这可行,但我知道必须有一种更有效的方法来利用一些 numpy 函数。
【问题讨论】:
标签: python arrays performance numpy