gpt4 book ai didi

torch - torch 中的列总和

转载 作者:行者123 更新时间:2023-12-01 10:36:04 31 4
gpt4 key购买 nike

我如何沿着 torch 中的列求和?我有一个 128*1024 的张量,我想通过对所有行求和得到一个 1*1024 的张量。

例如:一个:

1 2 3
4 5 6

我想要b

5 7 9

最佳答案

为此,您可以使用求和方法。

torch.sum(a,1)

通常,您可以指定要求和的任何轴。

torch.sum(a,axis)

(要对行求和,可以使用 axis=2)

关于torch - torch 中的列总和,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35214115/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com