I have a numpy array-like
x = np.zeros(4, dtype=np.int)
And I have a list of indices like [1, 2, 3, 2, 1] and I want to add 1 to the corresponding array elements, such that for each element in the index list, x is incremented at that position:
x = [0, 2, 2, 1]
I tried doing this using:
x[indices] += 1
But for some reason, it only updates the indices once, and if an index occurs more often than once it is not registered. I could of course just create a simple for loop but I was wondering if there is a one-line solution.
xis defined to be of length 3 but you later reference it as having 4 elements.add.atthat was provided to get around a buffering issue in+=.