Skip to content
This repository

Inconsistency in indexing 0-d arrays with Ellipsis #3017

Closed
Gitusername opened this Issue February 25, 2013 · 2 comments

3 participants

Gitusername njsmith
Gitusername

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[...]
array(1)
>>> a[(...,)]
array(1)
>>> a[...] = 4
>>> a
array(4)
>>> 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.

njsmith
Owner
Collaborator

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 referenced this issue from a commit September 16, 2013
Commit has since been removed from the repository and is no longer available.
dimasad dimasad referenced this issue from a commit in dimasad/numpy September 22, 2013
dimasad TST: added test for issue #3017.
Also changed style to please numpy developers.
094ebf7
njsmith njsmith closed this in 61e0f2b September 24, 2013
seberg referenced this issue from a commit September 26, 2013
Commit has since been removed from the repository and is no longer available.
seberg referenced this issue from a commit September 26, 2013
Commit has since been removed from the repository and is no longer available.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.