A = torch.tensor([2,4,5,6])
B = torch.cumprod(A,-1)
C = torch.cumsum(A,-1)
print(B)
print(C)
输出:
tensor([ 2, 8, 40, 240])
tensor([ 2, 6, 11, 17])
Process finished with exit code 0
本文介绍了如何在PyTorch中使用torch.cumprod()和torch.cumsum()函数计算向量A的累积乘积和累积和。通过实例展示了这两个函数的用法,并提供了输出结果。
A = torch.tensor([2,4,5,6])
B = torch.cumprod(A,-1)
C = torch.cumsum(A,-1)
print(B)
print(C)
输出:
tensor([ 2, 8, 40, 240])
tensor([ 2, 6, 11, 17])
Process finished with exit code 0
4377
3970
1578
2414

被折叠的 条评论
为什么被折叠?