torch.normal(means, std, out=None)
- means (Tensor) – 均值
- std (Tensor) – 标準差
- out (Tensor) – 可選的輸出張量
>>> n_data = torch.ones(5, 2)
>>> print(n_data)
tensor([[1., 1.],
[1., 1.],
[1., 1.],
[1., 1.],
[1., 1.]])
>>> print(n_data.shape)
torch.Size([5, 2])
>>> x0 = torch.normal(2*n_data, 1)
>>> print(x0)
tensor([[3.2688, 1.4834],
[1.8288, 0.7327],
[3.2382, 4.0835],
[2.8337, 2.1901],
[3.3097, 2.4447]])
#每個元素是從 均值=2*n_data中對應位置的取值,标準差為1的正态分布中随機生成的
>>> print(2*n_data)
tensor([[2., 2.],
[2., 2.],
[2., 2.],
[2., 2.],
[2., 2.]])
torch.max(參數1, 1)[1]
torch.max()[0], 隻傳回最大值的每個數
troch.max()[1], 隻傳回最大值的每個索引
torch.max()[1].data 隻傳回variable中的資料部分(去掉Variable containing:)
torch.max()[1].data.numpy() 把資料轉化成numpy ndarry
torch.max()[1].data.numpy().squeeze() 把資料條目中次元為1 的删除掉
torch.max(tensor1,tensor2) element-wise 比較tensor1 和tensor2 中的元素,傳回較大的那個值