本文作者:StubbornHuang
版权声明:本文为站长原创文章,如果转载请注明原文链接!
原文标题:Pytorch – torch.cat函数
原文链接:https://www.stubbornhuang.com/2441/
发布于:2022年12月08日 15:51:48
修改于:2022年12月08日 15:51:48

1 torch.cat函数
形式
torch.cat(tensors, dim=0, *, out=None)
功能
在指定的维度连接给定序列的张量,所有张量必须具有相同的形状(连接维度除外)或者为空。
参数
- tensors:相同形状的张量序列,非空张量必须具有相同形状(连接维度除外)
- dim:张量连接的维度
使用示例
import torch
if __name__ == '__main__':
a = torch.randn(size=(2, 2))
print(a)
b = torch.randn(size=(2, 2))
print(b)
c = torch.cat((a, b), dim=0)
print(c)
d = torch.cat((a, b), dim=1)
print(d)
输出
tensor([[ 0.8793, 0.3727],
[-2.3334, -1.4567]])
tensor([[-1.0906, -1.2683],
[ 0.7161, -0.5843]])
tensor([[ 0.8793, 0.3727],
[-2.3334, -1.4567],
[-1.0906, -1.2683],
[ 0.7161, -0.5843]])
tensor([[ 0.8793, 0.3727, -1.0906, -1.2683],
[-2.3334, -1.4567, 0.7161, -0.5843]])
当前分类随机文章推荐
- Pytorch – 使用torch.matmul()替换torch.einsum(‘nkctv,kvw->nctw’,(a,b))算子模式 阅读911次,点赞0次
- Pytorch - torch.unsqueeze和torch.squeeze函数 阅读233次,点赞0次
- Pytorch - torch.nn.Conv2d参数详解与使用 阅读317次,点赞0次
- Pytorch - nn.Transformer、nn.TransformerEncoderLayer、nn.TransformerEncoder、nn.TransformerDecoder、nn.TransformerDecoder参数详解 阅读1922次,点赞1次
- Pytorch - torch.stack参数详解与使用 阅读567次,点赞0次
- Pytorch - 内置的CTC损失函数torch.nn.CTCLoss参数详解与使用示例 阅读967次,点赞1次
- Pytorch - 模型微调时删除原有模型中的某一层的方法 阅读1657次,点赞0次
- Pytorch - transpose和permute函数的区别和用法 阅读1150次,点赞0次
- Pytorch - 内置的LSTM网络torch.nn.LSTM参数详解与使用示例 阅读1500次,点赞0次
- Pytorch - 使用Pyav解码视频文件并将视频帧转换为Pytorch tensor作为网络模型输入数据 阅读3682次,点赞0次
全站随机文章推荐
- C++ - queue存储动态指针时正确释放内存 阅读5234次,点赞2次
- 资源分享 - Level of Detail for 3D Graphics 英文高清PDF下载 阅读1748次,点赞1次
- 工具网站推荐 - 几个glTF模型在线预览网站 阅读786次,点赞0次
- C++ - 只有在Debug模式下才使用std::cout输出调试日志,Release发布版本不输出调试日志 阅读4160次,点赞0次
- 资源分享 - Production Volume Rendering - Design and Implementation 英文高清PDF下载 阅读1926次,点赞0次
- 资源分享 - Computational Geometry - Algorithms and Applications, Third Edition 英文高清pdf下载 阅读5355次,点赞1次
- C++11 - 使用std::chrono计算程序、函数运行时间 阅读2570次,点赞0次
- Duilib - 修改程序图标以及任务栏图标 阅读304次,点赞0次
- TensorRT - 自带工具trtexec的参数使用说明 阅读4156次,点赞0次
- 资源分享 - OpenGL 4.0 Shading Language Cookbook (First Edition) 英文高清PDF下载 阅读1582次,点赞0次
评论
167