torch.tensor张量的维度

问题描述

今天在对张量进行处理的时候,对于数据的维数绕晕了很久,特此记录。

案例

[[[1, 1, 1], [2, 2, 2]]] ----> 维度是 [1, 2, 3]

torch.tensor([[[1,1,1],[2,2,2]]]).shape
>torch.Size([1, 2, 3])

[[1, 1, 1], [2, 2, 2]] ----> 维度是 [2, 3]

torch.tensor([[1,1,1],[2,2,2]]).shape
>torch.Size([2, 3])

[[1,1,1]] ----> 维度是 [1, 3]

torch.tensor([[1,1,1]]).shape
>torch.Size([1, 3])

[1, 1, 1] ----> 维度是 [3]

torch.tensor([1,1,1]).shape
>torch.Size([3])

——2023.11.28

你可能感兴趣的:(Python学习,debug,深度学习,python,pytorch)