Pytorch 中 tensor 拼接 | torch.cat() 函数
【摘要】
https://pytorch.apachecn.org/docs/1.7/03.html
修改 第 1 列 数值为 2
# 初始化一个 tensor
tensor = torch.on...
修改 第 1 列 数值为 2
# 初始化一个 tensor
tensor = torch.ones(4,4)
tensor[:,1] = 2
print(tensor)
- 1
- 2
- 3
- 4
输出:
tensor([[1., 2., 1., 1.],
[1., 2., 1., 1.],
[1., 2., 1., 1.],
[1., 2., 1., 1.]])
- 1
- 2
- 3
- 4
横向拼接
t1 = torch.cat([tensor, tensor, tensor],dim = 1)
print(t1)
- 1
- 2
tensor([[1., 2., 1., 1., 1., 2., 1., 1., 1., 2., 1., 1.],
[1., 2., 1., 1., 1., 2., 1., 1., 1., 2., 1., 1.],
[1., 2., 1., 1., 1., 2., 1., 1., 1., 2., 1., 1.],
[1., 2., 1., 1., 1., 2., 1., 1., 1., 2., 1., 1.]])
- 1
- 2
- 3
- 4
竖向拼接
t1 = torch.cat([tensor, tensor, tensor],dim = 0)
print(t1)
- 1
- 2
tensor([[1., 2., 1., 1.],
[1., 2., 1., 1.],
[1., 2., 1., 1.],
[1., 2., 1., 1.],
[1., 2., 1., 1.],
[1., 2., 1., 1.],
[1., 2., 1., 1.],
[1., 2., 1., 1.],
[1., 2., 1., 1.],
[1., 2., 1., 1.],
[1., 2., 1., 1.],
[1., 2., 1., 1.]])
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
文章来源: positive.blog.csdn.net,作者:墨理学AI,版权归原作者所有,如需转载,请联系作者。
原文链接:positive.blog.csdn.net/article/details/113743630
【版权声明】本文为华为云社区用户转载文章,如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱:
cloudbbs@huaweicloud.com
- 点赞
- 收藏
- 关注作者
评论(0)