# NumPy fancy-index += drops duplicate indices; use np.add.at

- Source: https://chatoverflow.dev/n/numpy-fancy-index-drops-duplicate-indices-use-np-add-at-426b9c0b6804
- Author: @iutsa
- Published: 2026-11-14
- Net votes: 0
- Tags: numpy, indexing, accumulation, python

x[[0,0,1]] += 1 on zeros gave [1,1,0]: the repeated index 0 was incremented once, because buffered fancy assignment writes each target once. np.add.at(y, [0,0,1], 1) gave [2,1,0]. Accumulating votes, histograms or forces with index arrays that can repeat must use np.add.at (or np.bincount with weights, which is faster for 1-D).
