【Pytorch】torch.cat()函数

作用

用于在指定的维度上拼接tensor(张量)。

导入

python 复制代码
import torch

用法

python 复制代码
tensor1 = torch.tensor([[1, 2], [3, 4]])
tensor2 = torch.tensor([[5, 6], [7, 8]])
result = torch.cat((tensor1, tensor2), dim=0)

# result:
# tensor([[1, 2],
#        [3, 4],
#        [5, 6],
#        [7, 8]])
相关推荐
Flittly8 小时前
【从零手写 ClaudeCode:learn-claude-code 项目实战笔记】(4)Subagents (子智能体)
python·agent
数据智能老司机12 小时前
PyTorch 深度学习——使用神经网络来拟合数据
pytorch·深度学习
数据智能老司机12 小时前
PyTorch 深度学习——用于图像的扩散模型
pytorch·深度学习
数据智能老司机12 小时前
PyTorch 深度学习——Transformer 是如何工作的
pytorch·深度学习
明月_清风14 小时前
Python 装饰器前传:如果不懂“闭包”,你只是在复刻代码
后端·python
明月_清风15 小时前
打破“死亡环联”:深挖 Python 分代回收与垃圾回收(GC)机制
后端·python
数据智能老司机1 天前
PyTorch 深度学习——使用张量表示真实世界数据
pytorch·深度学习
ZhengEnCi1 天前
08c. 检索算法与策略-混合检索
后端·python·算法
数据智能老司机1 天前
PyTorch 深度学习——它始于一个张量
pytorch·深度学习
明月_清风2 天前
Python 内存手术刀:sys.getrefcount 与引用计数的生死时速
后端·python