Carlo
Carlo

Reputation: 1578

mxnet import nd or np to use arrays

I'm starting to study mxnet and gluon, but I'm getting somewhat confused about the usage of np/nd arrays.

both work (while, with mxnet 1.5.1, from mxnet import np fails).

Why is it possible to import np in the new version, if we had nd already? Are there any differences between arrays created from nd or np?
It seems that I can use mxnet features (such as attach_grad()) in both cases...for example, the following works:

from mxnet import np
array = np.array([1,2,3)
array.attach_grad()

Thanks!

Upvotes: 4

Views: 1177

Answers (1)

reminisce
reminisce

Reputation: 141

Here is the RFC explaining the motivation of introducing mx.np module. To give a couple of highlighted differences between mx.np and mx.nd modules:

  1. mx.np module adopts the official NumPy operator API, which has evolved for almost twenty years, to provide an easy transitioning experience for users coming from the NumPy world to deep learning, while the development of mx.nd module did not follow a well-established spec to define operator signatures, which sometimes caused confusions, e.g., dim vs axis.
  2. Operators registered in mx.np have highly compatible behaviors with the official NumPy operators, while mx.nd operators do not share such aspects. For example, zero-dim/scalar, zero-size, boolean tensors, and boolean indexing, are supported in mx.np, but not in mx.nd.

You can consider mx.np as an enhanced version of mx.nd in terms of usability, functionality, and performance. mx.nd will be gradually deprecated in the future releases.

Upvotes: 4

Related Questions