[Numpy-discussion] Easy way to vectorize a loop?

Stephen Simmons mail@stevesimmons....
Mon Mar 2 00:50:27 CST 2009


Hi,

Can anyone help me out with a simple way to vectorize this loop?

# idx and vals are arrays with indexes and values used to update array data
# data = numpy.ndarray(shape=(100,100,100,100), dtype='f4')
flattened = data.ravel()
for i in range(len(vals)):
    flattened[idx[i]]+=vals[i]


Many thanks!
Stephen


More information about the Numpy-discussion mailing list