[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Vectorization question



Given the following arrays

a = intarr(10)
x = [2, 2, 2, 3, 3, 4]
b = [1, 3, 4, 2, 1, 8]

How would I vectorize the following operation

for i = 0, n_elements(x) - 1 do a[x[i]] = a[x[i]] + b[i]

To achieve this result

print, a, format='(10i4)'
   0   0   8   3   8   0   0   0   0   0

In the real-world case where this occurs, I need to repeat this kind of
operation several hundred times, where the size of 'a' is around
1,000,000 and the size of 'x' is around 100,000 ('a' and 'b' are float
type in the real-world case).

Many thanks for any suggestions.

Cheers,
Liam.
http://cimss.ssec.wisc.edu/~gumley