前言
在上次学习创建数据张量的基础上,今天主要学习数据张量的计算。
提示:本文程序参考https://pytorch.org/tutorials/beginner/blitz/tensor_tutorial.html#sphx-glr-beginner-blitz-tensor-tutorial-py
from __future__ import print_function
import torch
一、复习
1.创建数据张量
代码
e = d.new_ones(5,8)
print(e)
f = torch.rand_like(e,dtype=torch.float)
print(f)
g = torch.randn_like(e,dtype=torch.float)
print(g)
结果
tensor([[1, 1, 1, 1, 1, 1, 1, 1],
[1, 1, 1, 1, 1, 1, 1, 1],
[1, 1, 1, 1, 1, 1, 1, 1],
[1, 1, 1, 1, 1, 1, 1, 1],
[1, 1, 1, 1, 1, 1, 1, 1]])
tensor([[0.6114, 0.1647, 0.3789, 0.8478, 0.9880, 0.9265, 0.8715, 0.9138],
[0.8915, 0.2455, 0.1023, 0.9978, 0.3499, 0.4577, 0.5852, 0.6608],
[0.1512, 0.6317, 0.3854, 0.7169, 0.6402, 0.6205, 0.8631, 0.7936],
[0.6953, 0.4689, 0.2848