2.1 张量Tensor
维度
0维: 标量
1维: 向量
4维: 图像
为什么说图片数据为4维张量呢?
解释:虽然描述一个图片用(width, height,channel),但是一般由于输入的图片数据不止一张,样本数大于1,因此描述方法为(sample_size, width, height, channel).
tensor 的创建方法
import torch
x = torch.tensor([5.5, 2])
x = torch.ones(4, 3, dtype=torch.long)
x = torch.zeros(4, 3, dtype = torch.float)
…(省略,可参看下图创建方法)
一般性操作方法
加法
(1)print(x + y)
(2)print(torch.add(x, y))
(3) 提供一个输出