We posted at same time. But the reason 0-D array isn't just a Python scalar is because it still has array attributes, most notably dtype. Now maybe 15 years ago NumPy could have created a bunch more custom numeric scalars for the different bit-lengths, but then we still wouldn't have the uniformity of having all the base array methods on those (or if we did, they'd be exactly what we have now, just called "enhanced scalar").
On Thu, Dec 12, 2019 at 8:23 PM Christopher Barker <python...@gmail.com> wrote: > 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/ > -- Keeping medicines from the bloodstreams of the sick; food from the bellies of the hungry; books from the hands of the uneducated; technology from the underdeveloped; and putting advocates of freedom in prisons. Intellectual property is to the 21st century what the slave trade was to the 16th.
_______________________________________________ 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/YK7FA3HGTDC2WAK54AH7W2WFTD3CRIOA/ Code of Conduct: http://python.org/psf/codeofconduct/