np.maximum.at
可用于执行
max
在特定指标下进行操作。
例如,如果我们有两个数组
arr1
和
arr2
比较和
indices
array,我们可以这样做:
arr1 = np.array([1, 2, 3, 4, 5])
arr2 = np.array([10, 1, 8, 7, 3])
indices = np.array([0, 1, 2, 1, 4])
# Perform in-place maximum update
np.maximum.at(arr1, indices, arr2)
print(arr1)
# Output: [10 7 8 4 5]
所以我相信在你的情况下,你可以这样做:
indices = coords[:, 0], coords[:, 1], coords[:, 2]
np.maximum.at(grid[0], indices, vals[:, 0])
np.maximum.at(grid[1], indices, vals[:, 1])
np.maximum.at(grid[2], indices, vals[:, 2])