On Fri, 2013-04-19 at 08:03 -0700, Chris Barker - NOAA Federal wrote:
On Apr 18, 2013, at 11:33 PM, Nathaniel Smith <njs@pobox.com> wrote:
On 18 Apr 2013 01:29, "Chris Barker - NOAA Federal" <chris.barker@noaa.gov> wrote:
This has been annoying, particular as rank-zero scalars are kind of a pain.
BTW, while we're on the topic, can you elaborate on this? I tend to think scalars (as opposed to 0d ndarrays) are kind of a pain, so I'm curious if you have specific issues you've run into with 0d ndarrays.
Well, I suppose what's really a pain is that we have both, and they are not the same, and neither can be used in all cases one may want.
In the case at hand, I really wanted a datetime64 scalar. By saving and re-loading in an npz, it got converted to a rank-zero array, which had different behavior. In this case, the frustrating bit was how to extract a scalar again ( which I really wanted to turn into a datetime object).
After the fact, I discovered .item(), which seems to do what I want.
Fun fact, array[()] will convert a 0-d array to a scalar, but do nothing (or currently create a view) for other arrays. Which is actually a good question. Should array[()] force a view or not? - Sebastian
On a phone now, so sorry about the lack of examples.
Note: I've lost track of why we need both scalers and rank-zero arrays. I can't help thinking that there could be an object that acts like a scalar in most contexts, but also has the array methods that make sense.
But I know it's far from simple.
-Chris
_______________________________________________ NumPy-Discussion mailing list NumPy-Discussion@scipy.org http://mail.scipy.org/mailman/listinfo/numpy-discussion