Alan G Isaac wrote: > On Thu, 07 Feb 2008, dmitrey apparently wrote: >> a = array((1.0, 2.0)) >> e = array(15) >> e *= a # ... yields error: > > You are trying to stuff in two values where > you have only allocated space for 1.
Exactly. but to expound a bit more: The ?= operators are in-place operators -- they attempt to modify the left hand side in-place. The regular math operators create a new array, which can be a different size than either of the two operands, thanks to "array broadcasting". x *= y should be the same as x = x*y iff the size of x*y is the same size as x. That's why: >>> e array(15) >>> a array([ 1., 2.]) >>> e*=a fails, but: >>> a*=e >>> a array([ 15., 30.]) works. One more note: you're doing element-wise array multiplication, not matrix multiplication -- a distinction that does matter sometimes. -Chris -- Christopher Barker, Ph.D. Oceanographer Emergency Response Division NOAA/NOS/OR&R (206) 526-6959 voice 7600 Sand Point Way NE (206) 526-6329 fax Seattle, WA 98115 (206) 526-6317 main reception [EMAIL PROTECTED] _______________________________________________ Numpy-discussion mailing list [email protected] http://projects.scipy.org/mailman/listinfo/numpy-discussion
