是的,可以做到,但是有点棘手:
# convert yourmulti-dim indices to flat indicesflat_idx = np.ravel_multi_index((Px, Py), dims=a.shape)# extract the unique indices and their positionunique_idx, idx_idx = np.unique(flat_idx, return_inverse=True)# Aggregate the repeated indices deltas = np.bincount(idx_idx, weights=x)# Sum them to your arraya.flat[unique_idx] += deltas



