1 NDArray基本用法
from mxnet import nd
#创建行向量
x=nd.arange(10)
print(x)
#获取形状
print(x.shape)
#获取元素总数
print(x.size)
#改变形状
y=x.reshape((2,5))
print(y)
#元素全0或1
a0=nd.zeros((2,3,4))
a1=nd.ones((2,3))
#列表方式创建
a2=nd.array([[2,1,4,3],[1,2,3,4],[4,3,2,1]])
#随机生成,正态分布
a3=nd.random.normal(0,1,shape=(3,4))
print(a0,a1,a2,a3)
![在这里插入图片描述](https://img-blog.csdnimg.cn/20190807204221278.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L1hpYW9iYWlMYXBsYWNl,size_16,color_FFFFFF,t_70)
2 NDArray运算
from mxnet import nd
X=nd.arange(12).reshape((3,4))
Y=nd.array([[2,1,4,3],[1,2,3,4],[4,3,2,1]])
print("X:",X)
print("Y:",Y)
print("X+Y:",X+Y)
print("X*Y:",X*Y)
print("X/Y:",X/Y)
print("指数:",X.exp())
print("矩阵乘法:",nd.dot(X,Y.T))