[SciPy-Dev] docstring standard: parameter shape description

Jonathan Guyer guyer@nist....
Tue Jan 29 09:09:54 CST 2013

On Jan 28, 2013, at 7:35 PM, Joe Harrington wrote:

> On Mon, 28 Jan 2013 13:47:26 -0800 Nathaniel Smith <njs@pobox.com> wrote:
>> "any size" should mean 0+. "absent" is not a size. If a function does
>> accept an optional final dimension, can we write that like 'shape (N,
>> D) or shape (N,)'?
> An array dimension cannot have 0 elements (the total size is the product
> of the shape tuple's elements).

That's not true. An array dimension certainly can have 0 elements:

>>> import numpy as np
>>> a = np.zeros((0,))
>>> b = np.zeros((1, 0))
>>> c = np.zeros((1, 0, 3))
>>> a.shape, b.shape, c.shape
((0,), (1, 0), (1, 0, 3))

For most applications, there is little utility in being able to declare an "empty" array, but you can certainly do it (and for us, it's handy for FiPy to partition PDE solutions across multiple processors without having to special-case any processors that don't get any solution nodes).

As we reported in http://projects.scipy.org/numpy/ticket/1171, the treatment of 0-length dimensions is buggy, but NumPy nonetheless allows for it.

More information about the SciPy-Dev mailing list