生成随机数
Torch
1. torch.rand 均匀分布
2. torch.randn 标准正态分布
3. torch,normal(means, std) 离散正态分布
4. torch.linsapce(start, end, steps=100) --> Tensor 线性间距向量
import torch
torch.tensor(5)
tensor(5)
# 1. torch.rand 均匀分布
a = torch.rand(2,3)
a
tensor([[0.2828, 0.0032, 0.2511],
[0.1414, 0.3980, 0.8461]])
# 2. 标准正太分布 torch.randn
b = torch.randn(2,3)
b
tensor([[ 0.0188, 2.1887, 1.1742],
[-0.8135, -2.7614, 0.1584]])
# 3. 离散正太分布 torch.normal(means, std,)
mean = torch.tensor([1,2,3],dtype=torch.float) #mean std的数据类型要保证
std = torch.tensor([1,1,1], dtype=torch.float)
torch.normal