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

Sebastian Berg sebastian@sipsolutions....
Fri Apr 19 13:00:11 CDT 2013

```On Fri, 2013-04-19 at 23:02 +0530, Robert Kern wrote:
> On Fri, Apr 19, 2013 at 9:40 PM, Sebastian Berg
> <sebastian@sipsolutions.net> wrote:
>
> > 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?
>
> Another fun fact: scalar[()] gives you a rank-0 array. :-)
>

Hahahaha, thats pretty (I would say bug).

> I think the array[()] behavior follows logically as a limiting form of
> multidimensional indexing. Given rank-3 array,
>
>   array[(i, j, k)] gives a scalar
>   array[(i, j)]    gives a rank-1 view of the last axis
>   array[(i,)]      gives a rank-2 view of the last 2 axes
>   array[()]        gives a rank-3 view of the last 3 axes (i.e. all of them)
>
> The rank-N-general rules look like so: For a rank-N array, an N-tuple
> gives a scalar. Subsequent (N-M)-tuples gives appropriate rank-M views
> picked out by the tuple.
>
> I can't explain the scalar[()] behavior, though. :-)
>

Another special case... It doesn't hit the normal indexing code, and so
it can never hit the tuple of integers special case to get converted
back to a scalar. But it also always gets converted to an array first.
So many special cases that are hard to miss, there is a reason I started
rewriting it ;).

Still not sure if one should force views sometimes though, but I doubt
it matters...

- Sebastian

> --
> Robert Kern
> _______________________________________________
> NumPy-Discussion mailing list
> NumPy-Discussion@scipy.org
> http://mail.scipy.org/mailman/listinfo/numpy-discussion
>

```