On Thu, Dec 12, 2019 at 4:39 PM Steven D'Aprano <st...@pearwood.info> wrote:

>
> Surely a zero-dimensional array ought to have no elements at all?
>

nope -- a zero-dimensional array is a scalar -- as distinct from a 1-d (or
2-d, or n-d) array that happens to have only one element.

in fact, numpy has a confusing (at least to me) distinction between a 0-D
array and a scalar, but that's an implementation detail :-)

In [2]: import numpy as np


In [3]: # a 3D array

In [5]: arr3 = np.ones((2,3,4))


In [6]: arr3.shape

Out[6]: (2, 3, 4)

In [7]: # index into it yields a 2D array

In [8]: arr2 = arr3[1]

In [9]: arr2.shape

Out[9]: (3, 4)

In [10]: # index into it yields a 1D array

In [11]: arr1 = arr2[1]

In [12]: arr1.shape

Out[12]: (4,)

In [13]: # index into it yields a 0D array

In [14]: arr0 =  arr1[0]

In [15]: arr0.shape

Out[15]: ()

-CHB

  - Desktop GUI and Web Development
  - wxPython, numpy, scipy, Cython
_______________________________________________
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to python-ideas-le...@python.org
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at 
https://mail.python.org/archives/list/python-ideas@python.org/message/KDPA3JVPDALHEJDHOEDNTDNXBKV64PQ7/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to