tensor常见的形式
1 | # Tensor常见形式 |
1 | import torch |
1 | # scalar |
tensor(42.)
1 | x.dim() |
0
1 | x.item() |
42.0
1 | # vector 向量 |
tensor([ 1.5000, -0.5000, 3.0000])
1 | v.dim() |
1
1 | v.size() |
torch.Size([3])
1 | # Matrix |
tensor([[1, 2],
[3, 4]])
1 | M.matmul(M) |
tensor([[ 7, 10],
[15, 22]])
1 | tensor([1,0]).matmul(M) |
tensor([1, 2])
1 | M * M |
tensor([[ 1, 4],
[ 9, 16]])
1 | tensor([1,2]).matmul(M) |
tensor([ 7, 10])
1 |
tensor常见的形式
https://zhangfuli.github.io/2020/09/01/tensor常见的形式/