[Numpy-discussion] Regression: in-place operations (possibly intentional)
Chris Barker
chris.barker at noaa.gov
Fri Sep 21 12:24:20 EDT 2012
On Thu, Sep 20, 2012 at 2:48 PM, Nathaniel Smith <njs at pobox.com> wrote:
> because a += b
> really should be the same as a = a + b.
I don't think that's the case - the inplace operator should be (and
are) more than syntactic sugar -- they have a different meaning and
use (in fact, I think they should't work at all for immutable, sbut i
guess the common increment-a-counter use was too good to pass up)
in the numpy case:
a = a + b
means "make a new array, from the result of adding a and b"
whereas:
a += b
means "change a in place by adding b to it"
In the first case, I'd expect the type of the result to be determined
by both a and b -- casting rules.
In the second case, a should certainly not be a different object, and
should not have a new data buffer, therefor should not change type.
Whereas the general case, there is no assumption that with:
a = b+c
a is the same type as either b or c, but certainly not the same object.
-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
Chris.Barker at noaa.gov
More information about the NumPy-Discussion
mailing list