0. 前提
import torch
## 使用阿里镜像安装torch
# pip install -i https://mirrors.aliyun.com/pypi/simple/ torch
1. 创建数组
- 按顺序创建张量(tensor)
x = torch.arange(12)
结果:tensor([ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11])
- 自定义创建tensor
torch.tensor([[1,2,3,4],[1,2,5,7],[6,2,9,3]])
结果:tensor([[1, 2, 3, 4],
[1, 2, 5, 7],
[6, 2, 9, 3]])
- 全0 、 全1 tensor
torch.zeros((2,3,4))
tensor([[[0., 0., 0., 0.],
[0., 0., 0., 0.],
[0., 0., 0., 0.]],
[[0., 0., 0., 0.],
[0., 0., 0., 0.],
[0., 0., 0., 0.]]])
torch.ones((2,3,4))
tensor([[[1., 1., 1., 1.],
[1., 1., 1., 1.],
[1., 1., 1., 1.]],
[[1., 1., 1., 1.],
[