The NDArray library in Apache MXNet defines the core data structure for all mathematical computations. NDArray supports fast execution on a wide range of hardware configurations and automatically parallelizes multiple operations across the available hardware.


The following example shows how you can create an NDArray from a regular Python list using the ‘array’ function.

import mxnet as mx
# create a 1-dimensional array with a python list
a = mx.nd.array([1,2,3])
# create a 2-dimensional array with a nested python list
b = mx.nd.array([[1,2,3], [2,3,4]])
{'a.shape':a.shape, 'b.shape':b.shape}


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.

  • performs dot product between the last axis of the first input array and the first axis of the second input, while uses the second last axis of the input array.

In addition, mxnet.ndarray.NDArray supports GPU computation and various neural network layers.


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.


NDArray Guide../../tutorials/packages/ndarray/

The NDArray guide. Start here!

NDArray API of MXNet


Imperative tensor operations using the NDArray API.

Sparse NDArray API of MXNet

Sparse routinessparse/index.html

Representing and manipulating sparse arrays.