快捷鍵

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

文件

Access comprehensive developer documentation for PyTorch

View Docs

Tutorials

Get in-depth tutorials for beginners and advanced developers

View Tutorials

Resources

Find development resources and get your questions answered

View Resources