[Numpy-discussion] numarray iterator question
Warren Weckesser
warren.weckesser@enthought....
Wed Mar 10 18:23:06 CST 2010
Neal Becker wrote:
> 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
>
>
Try this instead:
for u_row in u:
u_row[:] = u_row * 2
Warren
> 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)
>
> _______________________________________________
> NumPy-Discussion mailing list
> NumPy-Discussion@scipy.org
> http://mail.scipy.org/mailman/listinfo/numpy-discussion
>
More information about the NumPy-Discussion
mailing list