- 博客(2)
- 收藏
- 关注
原创 torch.scatter笔记
scatter()和scatter_()的作用是一样的,只不过 scatter() 不会直接修改原来的 Tensor,而 scatter_() 会。 import torch #定义一个张量 x = torch.tensor([[1,2,3],[4,5,6]]) print(x) #定义一个3×3零张量 z = torch.zeros((3,3),dtype = int) print(z) #定义索引 index=torch.LongTensor([[0,1,1],[1,2,1]]) print(...
2021-12-03 15:06:38
1396
原创 torch.gather用法笔记
gather的作用是在指定维度选择数据 import torch #定义一个张量 x = torch.tensor([[1,2,3],[4,5,6]]) print(x) #定义dim = 0 时的索引index0 index0 = torch.LongTensor([[0,1,1]]) print(index0) y = torch.gather(x, 0, index0) print(y) #定义dim = 1 时的索引index1 index1 = torch.LongTensor([[0,1,1
2021-12-03 13:40:39
1261
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人