《动手学习深度学习》 2 预备知识

本章地址:http://zh.diveintodeeplearning.org/chapter_prerequisite/index.html

2.2 数据操作

在MXNet中,NDArray是存储和变换数据的主要工具,它提供了GPU计算和自动求梯度的更多功能。

操作

from mxnet import nd

x = nd.arange(12)

x = nd.zeros((2,3,4))

x = nd.ones((3,4))

x = nd.array([[2,1], [3,9], [8,7]])

x = nd.random.normal(0, 1, shape=(3,4)) //它的每个元素都随机采样于均值为0 标准差为1 的正态分布。

x.shape

x.size

x.reshape


运算

X+Y

X*Y

X/Y

X==Y

X.sum()  或者 nd.sum(X)

Y.exp()  或者 nd.exp(X)

X.norm().asscalar() //asscalar 函数将结果变换为Python 中的标量

nd.dot(X, Y.T)

nd.contact(X, Y, dim=0)  //维度0代表行

nd.contact(X, Y, dim=1)  //维度1代表列

P30

猜你喜欢

转载自www.cnblogs.com/continuerun/p/10157188.html
今日推荐