如何将二维数组除以二维?(Python)



我有一个点数组,我想通过第二个维度将它们分成两个数组:

points_right = points[points[:, 0] > p0[0]]
points_left = points[points[:, 0] < p0[0]]

如何将这些点拆分为一个循环?

我认为np.split就是您想要的,只需使用axis=1即可。

拆分2x4矩阵的示例:

import numpy as np
pts = np.array([[1, 2, 3, 4], [5, 6, 7, 8]])
left_pts, right_pts = np.split(pts, indices_or_sections=2, axis=1)

原始矩阵(pts(:

[[1 2 3 4]
[5 6 7 8]]

left_pts:

[[1 2]
[5 6]]

right_pts:

[[3 4]
[7 8]]

https://numpy.org/doc/stable/reference/generated/numpy.split.html

最新更新