Numpy: Document ndindex(shape)

Created on 3 Jul 2020  ·  3Comments  ·  Source: numpy/numpy

This usage of ndindex:

>>> list(np.ndindex((3,2)))
[(0, 0), (0, 1), (1, 0), (1, 1), (2, 0), (2, 1)]

seems to work with

>>> np.__version__
'1.18.4'

but it's not documented. Is this usage intended to be allowed? (I'd like it to be, because if shape == 5 then np.index(shape) works while np.ndindex(*shape) does not.) If it is, could it be added to the docs?

04 - Documentation

Most helpful comment

Additionally, the type listing in the Parameters section is incorrect: both tuples and list of ints are allowed.

This has been fixed.

The signature of the np.ndindex docstring is inconsistent with the Parameters listing

I will be raising a PR for this :)

All 3 comments

We may want to make that version the preferred documented one, and just briefly mention the other option as well. In most cases (e.g. also arr.reshape() where we allow both, we prefer the tuple-version in the docs).

Just to clarify this a bit - I think there are two things that make the np.ndindex docstring confusing:

  1. The signature of the np.ndindex docstring is inconsistent with the Parameters listing
  2. Additionally, the type listing in the Parameters section is incorrect: both tuples and list of ints are allowed.

Additionally, the type listing in the Parameters section is incorrect: both tuples and list of ints are allowed.

This has been fixed.

The signature of the np.ndindex docstring is inconsistent with the Parameters listing

I will be raising a PR for this :)

Was this page helpful?
0 / 5 - 0 ratings