Skip to content
This repository has been archived by the owner on Nov 17, 2023. It is now read-only.

Indexing ndarray should give empty array output #17389

Closed
reminisce opened this issue Jan 21, 2020 · 1 comment
Closed

Indexing ndarray should give empty array output #17389

reminisce opened this issue Jan 21, 2020 · 1 comment

Comments

@reminisce
Copy link
Contributor

Description

When indexing an ndarray with an index greater than the dim size, it should produce an empty ndarray as in NumPy, instead of throwing an error.

>>> import mxnet as mx
>>> mx.npx.set_np()
>>> a = mx.np.arange(1)
>>> a
array([0.])
>>> a[1:]  # index exceeds dim size, should result in an empty array instead of throwing an error
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/ubuntu/unison/mxnet4/cpu/python/mxnet/numpy/multiarray.py", line 663, in __getitem__
    return self._slice(key.start, key.stop)
  File "/home/ubuntu/unison/mxnet4/cpu/python/mxnet/ndarray/ndarray.py", line 1343, in _slice
    start, stop, _ = _get_index_range(start, stop, self.shape[0])
  File "/home/ubuntu/unison/mxnet4/cpu/python/mxnet/ndarray/ndarray.py", line 3100, in _get_index_range
    raise IndexError('Slicing start %d exceeds limit of %d' % (start, length))
IndexError: Slicing start 1 exceeds limit of 1
>>> a.asnumpy()[1:]  # Okay in NumPy
array([], dtype=float32)
>>> a
array([0.])
>>> 

@Alicia1529

Alicia1529 added a commit to Alicia1529/incubator-mxnet that referenced this issue Jan 21, 2020
Alicia1529 added a commit to Alicia1529/incubator-mxnet that referenced this issue Jan 22, 2020
reminisce pushed a commit that referenced this issue Feb 6, 2020
@reminisce
Copy link
Contributor Author

Fixed in #17391

zheyuye pushed a commit to zheyuye/incubator-mxnet that referenced this issue Feb 19, 2020
anirudh2290 pushed a commit to anirudh2290/mxnet that referenced this issue May 29, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

1 participant