
pytorch使用
pytorch使用
good vegetable
这个作者很懒,什么都没留下…
展开
-
pytorch常用操作记录
tensor的按维度复制,使用场景,对query和doc算分的时候复制query。a = torch.FloatTensor([[1,2]])# shape = [1, 2]b = a.repeat(2, 4)#分别在各个维度上复制几次原创 2022-01-02 18:57:42 · 938 阅读 · 0 评论 -
torch.gather()取每行中不同列的元素
pytorch取每行中不同列的元素import torchscores = torch.tensor([ [1, 2, 3, 4], [5, 6, 7, 8], [9, 10, 11, 12]])label=torch.LongTensor([ [0],[1],[2] ])ans = scores.gather(1, label)print(ans)原创 2021-07-09 11:29:26 · 2956 阅读 · 1 评论