torch.cumsum¶
- torch.cumsum(input, dim, *, dtype=None, out=None) Tensor ¶
返回输入
input
沿着维度dim
的元素的累积和。例如,如果
input
是大小为 N 的向量,则结果也将是大小为 N 的向量,其元素为。- 参数
- 关键字参数
dtype (
torch.dtype
, 可选) – 返回张 Desired data type of returned tensor. 如果指定,则在执行操作之前,输入张量将转换为dtype
。这对于防止数据类型溢出很有用。默认值:None。out (Tensor, optional) – 输出张量。
示例
>>> a = torch.randint(1, 20, (10,)) >>> a tensor([13, 7, 3, 10, 13, 3, 15, 10, 9, 10]) >>> torch.cumsum(a, dim=0) tensor([13, 20, 23, 33, 46, 49, 64, 74, 83, 93])