快捷方式

torch.Tensor.size

Tensor.size(dim=None) torch.Size or int

返回 self tensor 的大小。如果未指定 dim,返回值將是 torch.Size(它是 tuple 的子類)。如果指定了 dim,則返回該維度的整數大小。

引數

dim (int, 可選) – 要獲取大小的維度。

示例

>>> t = torch.empty(3, 4, 5)
>>> t.size()
torch.Size([3, 4, 5])
>>> t.size(dim=1)
4

文件

訪問 PyTorch 的完整開發者文件

檢視文件

教程

獲取針對初學者和高階開發者的深度教程

檢視教程

資源

查詢開發資源並獲得問題解答

檢視資源