thomelane opened a new issue #13908: Support for Named Arrays
URL: https://github.com/apache/incubator-mxnet/issues/13908
 
 
   Seen a few mentions recently of `NamedTensors` which I think is a really 
good idea, and improves usability of deep learning frameworks. I would be great 
to think about how this functionality could be added to MXNet's NDArray: either 
by creating a NamedNDArray, or even better would be to include in NDArray 
directly.
   
   Using [Harvard's NamedTensor for 
PyTorch](https://github.com/harvardnlp/namedtensor) as inspiration, certain 
operators like reshaping, transposing and board-casting could be made a lot 
easier to use. Also see 
[`xarray`](http://xarray.pydata.org/en/stable/index.html#) project
   
   ## Code Samples
   
   Still import and use `nd` (ideally).
   
   ```
   from mxnet import nd
   ```
   
   Can optionally specify `axis_names` for new arrays.
   ```
   img = mx.nd.random.uniform(shape=(25, 32, 32, 3),
                              axis_names=("batch", "height", "width", 
"channels"))
   ```
   
   And if this is done, shapes and axes have (and can be referenced by) 
meaningful names.
   ```
   img.shape
   # OrderedDict([('batch', 6), ('height', 96), ('width', 96), ('channels', 3)])
   ```
   ```
   img = img.transpose(axes=("batch", "channels", "height", "width"))
   ```
   ```
   mean_img = img.mean(axis=("batch"))
   ```
   Will broadcast `horizontal_mask` across batch, channel and width.
   ```
   horizontal_mask = mx.nd.random.uniform(shape=(100,), axis_names=("height"))
   masked_img = img * horizontal_mask
   ```

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

Reply via email to