torch.cat(dim=-1)
时间: 2024-05-02 15:22:11 浏览: 114
torch-1.0.0
5星 · 资源好评率100%
torch.cat(dim=-1) is a PyTorch function that concatenates tensors along a given dimension. The "-1" dimension refers to the last dimension of the tensors being concatenated.
For example, if we have two tensors of shape (3, 4) and (3, 5), and we want to concatenate them along the last dimension, we can use the function as follows:
```
import torch
tensor1 = torch.randn(3, 4)
tensor2 = torch.randn(3, 5)
concatenated_tensor = torch.cat([tensor1, tensor2], dim=-1)
print(concatenated_tensor.shape)
```
Output:
```
torch.Size([3, 9])
```
The resulting tensor has a shape of (3, 9), where the last dimension has a size of 4+5=9.
阅读全文