I have data
A = np.array([1,2,3,4,5,6,7,8,9,10])
ind = np.array([0,1,4])
beg = 3
Typical size of A
and ind
is few millions.
What I want to do is modify data in A
with index ind+beg
.
for i in range(0,ind.size):
A[ind[i]+beg] += 1
Since the operation on A
(+1
) is almost the same as adding beg
to ind[i]
,
I want to avoid this.
In C-code, I usually do this by using pointer.
int* ptA = A-beg;
for(int i=0; i<indsize; i++) ptA[ind[i]]++;
Is it possible to do in python in a similar way, or should I stick to the first code?