快捷方式

torch.cumprod

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

返回 input 沿 dim 維度的累積乘積。

例如,如果 input 是一個大小為 N 的向量,結果也將是一個大小為 N 的向量,其元素如下所示。

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

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

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

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

示例

>>> a = torch.randn(10)
>>> a
tensor([ 0.6001,  0.2069, -0.1919,  0.9792,  0.6727,  1.0062,  0.4126,
        -0.2129, -0.4206,  0.1968])
>>> torch.cumprod(a, dim=0)
tensor([ 0.6001,  0.1241, -0.0238, -0.0233, -0.0157, -0.0158, -0.0065,
         0.0014, -0.0006, -0.0001])

>>> a[5] = 0.0
>>> torch.cumprod(a, dim=0)
tensor([ 0.6001,  0.1241, -0.0238, -0.0233, -0.0157, -0.0000, -0.0000,
         0.0000, -0.0000, -0.0000])

文件

查閱 PyTorch 的全面開發者文件

檢視文件

教程

獲取面向初學者和高階開發者的深度教程

檢視教程

資源

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

檢視資源