[Numpy-discussion] Behavior of array scalars
Sasha
ndarray at mac.com
Fri Feb 17 15:44:04 CST 2006
On 2/17/06, Travis Oliphant <oliphant at ee.byu.edu> wrote:
> ...
> Perhaps what is going on is that
> a += 10
> is begin translated to
> a = a + 10
> rather than
> add(a,10,a)
> I'll have to look deeper to see why.
It is actually being translated to "a = add(a,10,a)" by virtue of
array_inplace_add supplied in the inplace_add slot. Here is the
proof:
>>> a = array(0)
>>> a = b = array(0)
>>> a += 10
>>> b
array(10)
>>> a
10
Another way to explain it is to note that a += 10 is equivalent to "a
= a.__iadd__(10)" and a.__iadd__(10) is equivalent to "add(a, 10, a)".
This is not easy to fix because the real culprit is
>>> a = array(0)
>>> type(a) is type(a+a)
False
Maybe we can change ufunc logic so that when the output argument is
supplied it is returned without scalar conversion.
More information about the Numpy-discussion
mailing list