赞
踩
torch.ones — PyTorch 2.1 documentation
torch.ones(*size, *, out=None, dtype=None, layout=torch.strided, device=None, requires_grad=False) → Tensor
返回创建size大小的维度,里面元素全部填充为1
a = torch.ones(2, 3) # 相当于a = torch.ones((2, 3))及a = torch.ones(size=(2, 3))
b = torch.ones(5)
c = torch.ones(size=(3,4))
a,b,c
输出:
输出结果如下:
(tensor([[1., 1., 1.],
[1., 1., 1.]]),
tensor([1., 1., 1., 1., 1.]),
tensor([[1., 1., 1., 1.],
[1., 1., 1., 1.],
[1., 1., 1., 1.]]))
torch.full()以及torch.zeros()类似。
参考:
https://huaweicloud.csdn.net/63807f3cdacf622b8df88edb.html?spm=1001.2101.3001.6650.1&utm_medium=distribute.pc_relevant.none-task-blog-2%7Edefault%7ECTRLIST%7Eactivity-1-125103847-blog-103876885.235%5Ev39%5Epc_relevant_anti_t3&depth_1-utm_source=distribute.pc_relevant.none-task-blog-2%7Edefault%7ECTRLIST%7Eactivity-1-125103847-blog-103876885.235%5Ev39%5Epc_relevant_anti_t3&utm_relevant_index=2
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。