torch.randn(*sizes, out=None) → Tensor(张量)
返回一个张量,包含了从标准正态分布(均值为0,方差为 1)中抽取一组随机数,形状由可变参数sizes定义。 参数:
>>> import torch
>>> torch.randn(2,3)
tensor([[-1.0413, 0.8792, 2.1381],
[ 0.9541, -2.3019, 0.5490]])
>>>
>>> torch.randn(2,2,3)
tensor([[[ 0.4200, 0.4624, 0.3099],
[-0.1227, 0.2452, 0.9840]],
[[-0.8800, -0.5937, -1.4465],
[ 1.6523, -0.0170, -0.6393]]])
>>>
>>> torch.randn(2,2,2,3)
tensor([[[[-1.1649, -1.1810, -0.3619],
[-0.8433, -0.4411, 1.8187]],
[[ 0.4896, 0.4773, 0.0032],
[ 1.1269, 1.3638, 1.4495]]],
[[[-0.1959, 0.5646, 0.7001],
[ 0.6796, 0.1164, 1.6833]],
[[-0.2674, -0.2411, 1.5875],
[-0.2804, 1.4775, 0.2448]]]])
>>>
>>> a = torch.randn(2,2,2,3)
>>> torch.numel(a) # 计算tensor的元素个数(即矩阵的元素个数)
24
本文链接:http://task.lmcjl.com/news/5450.html