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)
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))
print("(行)连结:",nd.concat(X,Y,dim=0))
print("(列)连结:",nd.concat(X,Y,dim=1))
print("条件判别式:",X