.t()
Anonymous contributor
Published Sep 26, 2024
Contribute to Docs
In PyTorch, the .t()
method returns the transpose of a given 2D tensor. If the tensor is a 0D or 1D tensor, the method returns it as it is.
Syntax
torch.t(ten)
ten
: The tensor to be transposed.
Example
The following example demonstrates the usage of the .t()
method:
import torch# Define a tensorten = torch.tensor([[1, 2, 3],[4, 3, 8]])# Calculate the transpose of the tensorout = torch.t(ten)print(out)
The above code produces the following output:
tensor([[1, 4],[2, 3],[3, 8]])
Codebyte Example
The following codebyte example shows the use of the .t()
method:
All contributors
- Anonymous contributor
Contribute to Docs
- Learn more about how to get involved.
- Edit this page on GitHub to fix an error or make an improvement.
- Submit feedback to let us know how we can improve Docs.