Re: [Numpy-discussion] Behavior of array scalars
by Travis Oliphant other posts by this author
Feb 17 2006 3:04PM messages near this date
[Numpy-discussion] Behavior of array scalars
|
Re: [Numpy-discussion] Behavior of array scalars
Christopher Barker wrote:
> Hi all,
>
> It just dawned on my that the numpy array scalars might give something
> I have wanted once in a while: mutable scalars. However, it seems that
> we almost, but no quite, have them. A few questions:
NumPy (starting with Numeric) has always had this love-hate relationship
with zero-dimensional arrays. We use them internally to simplify the
code, but try not to expose them to the user. Ultimately, we couldn't
figure out how to do that cleanly and so we have the current compromise
situation where 0-d arrays are available but treated as second-class
citizens. Thus, we still get funny behavior in certain circumstances.
I think you found another such quirky area.
I'm open to suggestions.
To analyze this particular case...
The a+= 10
operation should be equivalent to add(a,10,a).
Note that explicitly writing
add(a,10,a)
returns a scalar (all ufuncs return scalars if 0-d arrays are the
result). But, a is modified in-place as you wanted.
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.
-Travis
-------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc. Do you grep through log files
for problems? Stop! Download the new AJAX search engine that makes
searching your log files as easy as surfing the web. DOWNLOAD SPLUNK!
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=103432&bid=230486&dat=121642
_______________________________________________
Numpy-discussion mailing list
Numpy-discussion@[...].net
https://lists.sourceforge.net/lists/listinfo/numpy-discussion
Thread:
Christopher Barker
Travis Oliphant
Sasha
Travis Oliphant
Christopher Barker
Sasha
Travis Oliphant
David M. Cooke
Sasha
Travis Oliphant
Travis Oliphant
Sasha
Travis Oliphant
Sasha
Alexander Belopolsky
Sasha
|