On this page
torch.Tensor.size
Tensor.size(dim=None) → torch.Size or int
-
Returns the size of the
self
tensor. Ifdim
is not specified, the returned value is atorch.Size
, a subclass oftuple
. Ifdim
is specified, returns an int holding the size of that dimension.- Parameters
-
dim (int, optional) – The dimension for which to retrieve the size.
Example:
>>> t = torch.empty(3, 4, 5) >>> t.size() torch.Size([3, 4, 5]) >>> t.size(dim=1) 4
© 2024, PyTorch Contributors
PyTorch has a BSD-style license, as found in the LICENSE file.
https://pytorch.org/docs/2.1/generated/torch.Tensor.size.html