我有一个三维坐标系(X,Y,Z)中点的列表。此外,每个点都被分配了一个浮点值v,因此单个点可以描述为(x,y,z,v)。该列表表示为形状为(N,4)的numpy数组。对于每个2d位置x,y,我需要获取v的最大值。一种直接但计算量昂贵的方法是:
有没有更多“numpy”方法,能够在性能方面带来一些收益?
for index in range(points.shape[0]):
x = points[index, 0]
y = points[index, 1]
v = points[index, 3]
maxes[x, y] = np.max(maxes[x, y], v)
有没有更多“numpy”方法,能够在性能方面带来一些收益?
np.max(points[:, 3])
不足够? - Cedric H.x, y
对的最大值。基本上,按x, y
分组并找到每个组的最大值。 - Giacomo Alzetta