[Tutor] normalize an array

John washakie at gmail.com
Fri Nov 26 17:10:07 CET 2010


I know this is a simple problem, but I want to do it the most
efficient way (that is vectorized...)

import numpy as np

a = np.array(([1,2,3,4],[1,.2,3,4],[1,22,3,4]))
b = np.sum(a,axis=1)

for i,elem in enumerate(a):
    a[i,:] = elem/b[i]



suggestions?


More information about the Tutor mailing list