[Numpy-discussion] numpy scalars and savez -- bug?

Chris Barker - NOAA Federal chris.barker at noaa.gov
Fri Apr 19 11:15:39 EDT 2013


Robert,

As I think you wrote the code, you may have a quick answer:

Given that numpy scalars do exist, and have their uses -- I found this
wiki page to remind me:

http://projects.scipy.org/numpy/wiki/ZeroRankArray

It would be nice if the .npy format could support them. Would that be
a major change? I'm trying to decide if this bugs me enough to work on
that.

-Chris


On Fri, Apr 19, 2013 at 8:03 AM, Chris Barker - NOAA Federal
<chris.barker at noaa.gov> wrote:
> On Apr 18, 2013, at 11:33 PM, Nathaniel Smith <njs at pobox.com> wrote:
>
> On 18 Apr 2013 01:29, "Chris Barker - NOAA Federal" <chris.barker at 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.
>
> 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
>
>



-- 

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