赞
踩
区分上述四个函数:
1. torch.rand
#均匀分布采样 torch.rand(*sizes, out=None) → Tensor #*sizes指定张量的形状、out指定数据存储的位置 import torch a=torch.rand([3,4]) print(a) ''' tensor([[0.7305, 0.5913, 0.0737, 0.5401], [0.9628, 0.0018, 0.7095, 0.7052], [0.2917, 0.1240, 0.6389, 0.2412]]) ''' torch.rand([3,4],out=a) print(a) ''' tensor([[0.3986, 0.1947, 0.7191, 0.2240], [0.8659, 0.5979, 0.0932, 0.6231], [0.6283, 0.3945, 0.1363, 0.0065]]) '''
2. torch.randn
#采样标准正态分布
torch.randn(*sizes, out=None) → Tensor
#参数含义同上
3. torch.normal
#采样离散正态分布,相比于torch.randn,每一个数字都可以来自不同均值和方差的正态分布
#有以下三种形式
torch.normal(mean=0.0, std, out=None) → Tensor #mean为标量(共用),std为tensor指定shape和每个位置的方差
torch.normal(mean, std=1.0, out=None) → Tensor #std为标量(共用),mean为tensor指定shape和每个位置的均值
torch.normal(mean, std, size, out=None) → Tensor #std和mean都是标量,此时需要size指定shape
4. torch.linespace
#线性间距采样
torch.linspace(start, end, steps=100, out=None) → Tensor
#start起点,end终点,steps点数
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。