torch.cat和torch.stack的区别
torch.cat和torch.stack的区别
stack操作后会在原来的基础上再增加一维,比如原来两个tensor的维度都是3维,经过stack后的结果为4维tensor; 而cat并不会改变维度数,只会在某一个维度上叠加。
import torch
# torch.cat函数
x = torch.rand((3, 240, 120))
y = torch.rand((3, 240, 120))
print(torch.cat((x, y), dim=0).shape) # torch
原创
2022-05-07 15:48:22 ·
280 阅读 ·
0 评论