I have a numpy array A and I want to modify values in it using a indexing list B. But the thing is in my slicing I can have an element of the array multiple times... This example will explain better what I mean by that :
import numpy as np
A = np.arange(5) + 0.5
B = np.array([0, 1, 0, 2, 0, 3, 0, 4])
print A[B]
returns as expected [ 0.5 1.5 0.5 2.5 0.5 3.5 0.5 4.5].
However if I do that :
A[B] += 1.
print A
I was expecting to obtain [ 4.5 2.5 3.5 4.5 5.5] as the first element is repeated 4 times in the indexing vector B, but it returns [ 1.5 2.5 3.5 4.5 5.5].
So how can I do what I actually wanted to do? (without using any loop as I'm using that on very large arrays)
[ 4.5 2.5 3.5 4.5]which has only 4 elements, and you have 5 indices in B. Why one element is missing?[15 23 34 45 56]not[12 23 34 45 56]as the first element of A is repeated 4 times in the indexing list B, it should be submitted 4 times to the +1 operation... at least that's what I wanna do in the end. Any idea how?