Inconsistency in indexing 0-d arrays with Ellipsis #3017

Gitusername opened this Issue Feb 25, 2013 · 2 comments


None yet

3 participants


Attempting to set the element of a 0-d array by indexing it with (...,) causes an IndexError, but similar operations with Ellipsis work correctly:

>>> a = numpy.array(1)
>>> a[...]
>>> a[(...,)]
>>> a[...] = 4
>>> a
>>> a[(...,)] = 5
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
IndexError: 0-d arrays can't be indexed.

I assume this should be allowed? It came up in some code along the following lines:

a = numpy.zeros(b.shape + c.shape)
for i in numpy.ndindex(c.shape):
    a[(...,) + i] = something

which fails to work when c is zero-dimensional.

NumPy member
NumPy member

You probably got that already, but if you need a workaround, c[(slice(None),) * a.ndim + index] will work, since the empty tuple does not have this issue.

@dimasad dimasad added a commit to dimasad/numpy that referenced this issue Sep 22, 2013
@dimasad dimasad TST: added test for issue #3017.
Also changed style to please numpy developers.
@njsmith njsmith closed this in 61e0f2b Sep 24, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment