searchusermenu
  • 发布文章
  • 消息中心
点赞
收藏
评论
分享
原创

tensor中0维、1维、2维、3维(高)

2024-11-04 09:32:44
2
0
# 0维Tensor:也就是一个标量(Scalar),它没有维度,
# 1维Tensor:也称作向量(Vector),它有一个维度
# 2维Tensor:也称作矩阵(Matrix),它有两个维度
# 3维Tensor:也叫高维Tensor(>=3), 它有3个维度可以想象为一个数据立方体

import torch

x = torch.tensor(1)
print(x.shape, x.size(), x.dim())

x = torch.tensor([1])
print(x.shape, x.size(), x.dim())

x = torch.tensor([1, 2, 3])
print(x.shape, x.size(), x.dim())

x = torch.tensor([[1, 2, 3], [4, 5, 6]])
print(x.shape, x.size(), x.dim())

x = torch.tensor([[1]])
print(x.shape, x.size(), x.dim())

x = torch.tensor([[1, 2, 3]])
print(x.shape, x.size(), x.dim())

x = torch.tensor([[1], [1], [1]])
print(x.shape, x.size(), x.dim())

x = torch.tensor([[[1]]])
print(x.shape, x.size(), x.dim())
x = torch.tensor([[[1, 2, -1], [3, 4, -1]], [[5, 6, -1], [7, 8, -1]]])
print(x.shape, x.size(), x.dim())

'''
torch.Size([]) torch.Size([]) 0
torch.Size([1]) torch.Size([1]) 1
torch.Size([3]) torch.Size([3]) 1
torch.Size([2, 3]) torch.Size([2, 3]) 2
torch.Size([1, 1]) torch.Size([1, 1]) 2
torch.Size([1, 3]) torch.Size([1, 3]) 2
torch.Size([3, 1]) torch.Size([3, 1]) 2
torch.Size([1, 1, 1]) torch.Size([1, 1, 1]) 3
torch.Size([2, 2, 3]) torch.Size([2, 2, 3]) 3
'''
0条评论
作者已关闭评论
Top123
33文章数
3粉丝数
Top123
33 文章 | 3 粉丝
Top123
33文章数
3粉丝数
Top123
33 文章 | 3 粉丝
原创

tensor中0维、1维、2维、3维(高)

2024-11-04 09:32:44
2
0
# 0维Tensor:也就是一个标量(Scalar),它没有维度,
# 1维Tensor:也称作向量(Vector),它有一个维度
# 2维Tensor:也称作矩阵(Matrix),它有两个维度
# 3维Tensor:也叫高维Tensor(>=3), 它有3个维度可以想象为一个数据立方体

import torch

x = torch.tensor(1)
print(x.shape, x.size(), x.dim())

x = torch.tensor([1])
print(x.shape, x.size(), x.dim())

x = torch.tensor([1, 2, 3])
print(x.shape, x.size(), x.dim())

x = torch.tensor([[1, 2, 3], [4, 5, 6]])
print(x.shape, x.size(), x.dim())

x = torch.tensor([[1]])
print(x.shape, x.size(), x.dim())

x = torch.tensor([[1, 2, 3]])
print(x.shape, x.size(), x.dim())

x = torch.tensor([[1], [1], [1]])
print(x.shape, x.size(), x.dim())

x = torch.tensor([[[1]]])
print(x.shape, x.size(), x.dim())
x = torch.tensor([[[1, 2, -1], [3, 4, -1]], [[5, 6, -1], [7, 8, -1]]])
print(x.shape, x.size(), x.dim())

'''
torch.Size([]) torch.Size([]) 0
torch.Size([1]) torch.Size([1]) 1
torch.Size([3]) torch.Size([3]) 1
torch.Size([2, 3]) torch.Size([2, 3]) 2
torch.Size([1, 1]) torch.Size([1, 1]) 2
torch.Size([1, 3]) torch.Size([1, 3]) 2
torch.Size([3, 1]) torch.Size([3, 1]) 2
torch.Size([1, 1, 1]) torch.Size([1, 1, 1]) 3
torch.Size([2, 2, 3]) torch.Size([2, 2, 3]) 3
'''
文章来自个人专栏
云原生最佳实践
33 文章 | 1 订阅
0条评论
作者已关闭评论
作者已关闭评论
0
0