-
Notifications
You must be signed in to change notification settings - Fork 6.8k
nd.slice errors out when end=-1 and step=-1 #14105
Comments
Hey, this is the MXNet Label Bot. |
@mxnet-label-bot add [Python, NDArray, Operator, Bug] |
According to numpy, this should return an empty array. Since MXNet does not support emtpy array in computation, it simply throws exception. So there is nothing wrong for now until we support empty arrays which has been planned. >>> import numpy as np
>>> data = np.random.uniform(size=(4,))
>>> data
array([0.19584417, 0.05437645, 0.73802081, 0.20259332])
>>> data[2:-1:-1]
array([], dtype=float64) |
@reminisce numpy behavior seems to be inconsistent . For example
end = 0 returns the two element array till index 1. end = -1 instead of returning 3 element array returns empty array. Ideally it should return the three element array. Otherwise there is no way to include the 0th index with negative step. |
Opened an issue with numpy for the same numpy/numpy#13123 |
According to numpy, -1 corresponds to last element of array. >>> data = np.random.uniform(size=(4,))
>>> data
array([0.39041899, 0.65619514, 0.79147856, 0.71647746])
>>> data[2:None:-1]
array([0.79147856, 0.65619514, 0.39041899])
>>> data[2::-1]
array([0.79147856, 0.65619514, 0.39041899]) |
Closing this issue as the behavior is consistent with numpy. Here is how we can get the element at 0-th index with MXNet NDArray.
Note: |
Description
For
mxnet.ndarray.slice(data, begin, end)
, ifend=-1
andstep=-1
, it does not return a reversed tensor. Instead, it gives an invalid data error.Minimum reproducible environment
Expected output:
[1.0434405 0.7740038 2.2122064]
Outputs:
The text was updated successfully, but these errors were encountered: