NDArray
在MxNet中,NDArray是所有数学运算的核心数据结构,与Numpy中的ndarray相似。与numpy相比,MxNet中的NDArray有以下的优点:
- 对平台通用:在CPU GPU下都兼容
- 可以自动地并行化
NDArray的创建
在Mxnet中,NDArray实质上指的是mx.nd.array,并且有以下几种常用的属性:
- ndarray.shape: The dimensions of the array. It is a tuple of integers
indicating the length of the array along each axis. For a matrix with
n rows and m columns, its shape will be (n, m). - ndarray.dtype: A numpy type object describing the type of its elements.
- ndarray.size: the total number of components in the array - equal to the product of the components of its shape
- ndarray.context: The device on which this array is stored, e.g. cpu() or gpu(1).
通过常量来创建:
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