快捷方式

torch.cumsum

torch.cumsum(input, dim, *, dtype=None, out=None) Tensor

返回輸入張量 input 在維度 dim 上的累積和。

例如,如果 input 是一個大小為 N 的向量,則結果也將是一個大小為 N 的向量,其元素為:

yi=x1+x2+x3++xiy_i = x_1 + x_2 + x_3 + \dots + x_i
引數
  • input (Tensor) – 輸入張量。

  • dim (int) – 進行操作的維度

關鍵字引數
  • dtype (torch.dtype, 可選) – 返回張量的期望資料型別。如果指定,在執行操作之前,輸入張量會被轉換為 dtype 型別。這對於防止資料型別溢位非常有用。預設值: None。

  • out (Tensor, 可選) – 輸出張量。

示例

>>> 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])

文件

訪問 PyTorch 的全面開發者文件

檢視文件

教程

獲取針對初學者和高階開發者的深度教程

檢視教程

資源

查詢開發資源並獲得問題解答

檢視資源