form mxnet import ndarray as nd
NDArray
0 矩阵
nd.zeros((3,4))
1 矩阵
nd.ones((3,4))
创建矩阵
nd.array([[1,2],[3,4]])
随机矩阵 均值 a 方差 b nxm
nd.random_normal(a,b,shape=(n,m))
大小 shape
个数 size
运算
+ ×
指数 nd.exp()
点乘 nd.dot()
转置 y.T
广播
形状不一样,复制
与NumPy的转换
import numpy as np
x = np.ones((2,3))
y = nd.array(x) # numpy -> mxnet
z = y.asnumpy() # mxnet -> numpy
替换
通过[:]写到一个之前开好的数组里
z[:] = x + y
截取
从a到b行:x[a:b]
指定位置:x[a,b]
多维:x[1:2,1:3]
autograd
import mxnet.ndrray as nd
import mxnet.autograd as ag
申请空间
x.attah_grad()
显式求导的程序
with ag.record():
y = x * 2
z = y * x
进行求导
z.backward()