.. currentmodule:: mxnet.ndarray
This document lists the routines of the n-dimensional array package:
.. autosummary:: :nosignatures: mxnet.ndarray
The NDArray
API, defined in the ndarray
(or simply nd
) package, provides imperative tensor operations on CPU/GPU. An NDArray
represents a multi-dimensional, fixed-size homogenous array.
>>> x = mx.nd.array([[1, 2, 3], [4, 5, 6]]) >>> type(x) <class 'mxnet.ndarray.NDArray'> >>> x.shape (2, 3) >>> y = x + mx.nd.ones(x.shape)*3 >>> print(y.asnumpy()) [[ 4. 5. 6.] [ 7. 8. 9.]] >>> z = y.as_in_context(mx.gpu(0)) >>> print(z) <NDArray 2x3 @gpu(0)>
A detailed tutorial is available at NDArray - Imperative tensor operations on CPU/GPU.
.. note:: ``mxnet.ndarray`` is similar to ``numpy.ndarray`` in some aspects. But the differences are not negligible. For instance: - ``mxnet.ndarray.NDArray.T`` does real data transpose to return new a copied array, instead of returning a view of the input array. - ``mxnet.ndarray.dot`` performs dot product between the last axis of the first input array and the first axis of the second input, while `numpy.dot` uses the second last axis of the input array. In addition, ``mxnet.ndarray.NDArray`` supports GPU computation and various neural network layers. .. note:: ``ndarray`` provides almost the same routines as ``symbol``. Most routines between these two packages share the source code. But ``ndarray`` differs from ``symbol`` in few aspects: - ``ndarray`` adopts imperative programming, namely sentences are executed step-by-step so that the results can be obtained immediately whereas ``symbol`` adopts declarative programming. - Most binary operators in ``ndarray`` such as ``+`` and ``>`` have broadcasting enabled by default.
In the rest of this document, we first overview the methods provided by the ndarray.NDArray
class, and then list other routines provided by the ndarray
package.
NDArray
class.. autosummary:: :nosignatures: NDArray.shape NDArray.size NDArray.context NDArray.dtype
.. autosummary:: :nosignatures: NDArray.copy NDArray.copyto NDArray.as_in_context NDArray.asnumpy NDArray.asscalar NDArray.astype
.. autosummary:: :nosignatures: NDArray.T NDArray.reshape NDArray.broadcast_to
.. autosummary:: :nosignatures: NDArray.__add__ NDArray.__sub__ NDArray.__rsub__ NDArray.__neg__ NDArray.__mul__ NDArray.__div__ NDArray.__rdiv__ NDArray.__mod__ NDArray.__rmod__ NDArray.__pow__
.. autosummary:: :nosignatures: NDArray.__iadd__ NDArray.__isub__ NDArray.__imul__ NDArray.__idiv__ NDArray.__imod__
.. autosummary:: :nosignatures: NDArray.__lt__ NDArray.__le__ NDArray.__gt__ NDArray.__ge__ NDArray.__eq__ NDArray.__ne__
.. autosummary:: :nosignatures: NDArray.__getitem__ NDArray.__setitem__
.. autosummary:: :nosignatures: NDArray.wait_to_read
.. autosummary:: :nosignatures: array empty zeros ones full arange load save
.. autosummary:: :nosignatures: cast reshape flatten expand_dims
.. autosummary:: :nosignatures: broadcast_to broadcast_axes repeat tile pad
.. autosummary:: :nosignatures: transpose swapaxes flip
.. autosummary:: :nosignatures: concat split
.. autosummary:: :nosignatures: slice slice_axis take batch_take one_hot pick
.. autosummary:: :nosignatures: add subtract negative multiply divide modulo dot batch_dot add_n
.. autosummary:: :nosignatures: sin cos tan arcsin arccos arctan degrees radians
.. autosummary:: :nosignatures: sinh cosh tanh arcsinh arccosh arctanh
.. autosummary:: :nosignatures: sum nansum prod nanprod mean max min norm
.. autosummary:: :nosignatures: round rint fix floor ceil trunc
.. autosummary:: :nosignatures: exp expm1 log log10 log2 log1p
.. autosummary:: :nosignatures: power sqrt rsqrt square
.. autosummary:: :nosignatures: equal not_equal greater greater_equal lesser lesser_equal
.. autosummary:: :nosignatures: random_uniform random_normal random_gamma random_exponential random_poisson random_negative_binomial random_generalized_negative_binomial mxnet.random.seed
.. autosummary:: :nosignatures: sort topk argsort argmax argmin
.. autosummary:: :nosignatures: maximum minimum clip abs sign gamma gammaln
.. autosummary:: :nosignatures: FullyConnected Convolution Activation BatchNorm Pooling SoftmaxOutput softmax log_softmax
.. autosummary:: :nosignatures: Correlation Deconvolution RNN Embedding LeakyReLU InstanceNorm L2Normalization LRN ROIPooling SoftmaxActivation Dropout BilinearSampler GridGenerator UpSampling SpatialTransformer LinearRegressionOutput LogisticRegressionOutput MAERegressionOutput SVMOutput softmax_cross_entropy smooth_l1 IdentityAttachKLSparseReg MakeLoss BlockGrad Custom
.. automodule:: mxnet.ndarray :members: .. automodule:: mxnet.random :members: