Create a 2D tensor with shape (2, 3) and values [[1, 2, 3], [4, 5, 6]]. Transpose the tensor.
时间: 2024-05-09 08:21:37 浏览: 143
一个2D转3D的方法
Sure, the code to create the 2D tensor and transpose it using Python is:
```
import torch
# create 2D tensor
tensor_2d = torch.tensor([[1, 2, 3], [4, 5, 6]])
# transpose tensor
tensor_transposed = tensor_2d.transpose(0, 1)
print(tensor_transposed)
```
The output will be:
```
tensor([[1, 4],
[2, 5],
[3, 6]])
```
Hope this helps!
阅读全文