我分两个数组numpy的阵列,XY坐标:比较不同尺寸
basic_pts = np.array([[0, 0], [1, 0], [2, 0], [0, 1], [1, 1], [0, 2]])
new_pts = np.array([[2, 2], [2, 1], [0.5, 0.5], [1.5, 0.5]])
至于结果,我从阵列希望new_pts
只有那些点,即履行存在basic_pts
没有点的条件更大的x和y值。因此,结果将是
res_pts = np.array([[2, 2], [2, 1], [1.5, 0.5]])
我有工作,但由于带有列表理解的工作是不适合数据量较大的一个解决方案。
x_cond = ([basic_pts[:, 0] > x for x in new_pts[:, 1]])
y_cond = ([basic_pts[:, 1] > y for y in new_pts[:, 1]])
xy_cond_ = np.logical_and(x_cond, y_cond)
xy_cond = np.swapaxes(xy_cond_, 0, 1)
mask = np.invert(np.logical_or.reduce(xy_cond))
res_pts = new_pts[mask]
有没有更好的方法来解决这个问题,只能用numpy和没有列表理解?
这是我的想法为好;不过要注意的是,它最终会创建一个中间数组''(len(basic_pts),len(new_pts))'中间数组,这可能会占用大量内存(OP提到'大量数据') – val
@val是的,这可能是一个问题具有非常大的数据量。感谢您指出了这一点! – Divakar
令人惊叹 - 谢谢。有很多东西要学习...... – Geri