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

Stephen Simmons mail at stevesimmons.com
Mon Mar 2 01:50:27 EST 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