[Python-Dev] Pre-PEP: Allow Empty Subscript List Without Parentheses

Tim Hochberg tim.hochberg at ieee.org
Fri Jun 9 20:09:22 CEST 2006

Guido van Rossum wrote:
> On 6/9/06, Nicko van Someren <nicko at nicko.org> wrote:
> The language doesn't have zero-dimensional arrays, although it doesn't
> prevent users from defining them. but why would one want to index a
> zero-dimensional array, since it has no dimensions? It should be
> written as x, not x[].

In Numpy, a 0-D array [for example, array(5)] is almost, but not quite, 
equivalent to  scalar [for example, 5]. The difference is that the 
former is mutable. Thus "a[()] = 3" will set the value of a 0-D array to 
3 and "a[()]" will extract the current, scalar value of a, for instance 
if you need a hashable object.

Whether that makes x[] desirable I won't venture an opinion. I don't see 
a lot of use of 0-D arrays in practice.



More information about the Python-Dev mailing list