[Numpy-discussion] numarray iterator question

Neal Becker ndbecker2@gmail....
Wed Mar 10 18:19:07 CST 2010


This is a bit confusing to me:

import numpy as np

u = np.ones ((3,3))

for u_row in u:
    u_row = u_row * 2  << doesn't work

print u
[[ 1.  1.  1.]
 [ 1.  1.  1.]
 [ 1.  1.  1.]]

for u_row in u:
    u_row *= 2  << does work
[[ 2.  2.  2.]
 [ 2.  2.  2.]
 [ 2.  2.  2.]]

Naively, I'm thinking a *= b === a = a * b.

Is this behavior expected?  I'm asking because I really want:

u_row = my_func (u_row)



More information about the NumPy-Discussion mailing list