當前位置: 首頁>>編程示例 >>用法及示例精選 >>正文


Python PyTorch cummax用法及代碼示例

本文簡要介紹python語言中 torch.cummax 的用法。

用法:

torch.cummax(input, dim, *, out=None)

參數

  • input(Tensor) -輸入張量。

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

關鍵字參數

out(tuple,可選的) -兩個輸出張量(值,索引)的結果元組

返回一個命名元組 (values, indices) 其中 values 是維度 diminput 的元素的累積最大值。並且 indices 是在維度 dim 中找到的每個最大值的索引位置。

例子:

>>> a = torch.randn(10)
>>> a
tensor([-0.3449, -1.5447,  0.0685, -1.5104, -1.1706,  0.2259,  1.4696, -1.3284,
     1.9946, -0.8209])
>>> torch.cummax(a, dim=0)
torch.return_types.cummax(
    values=tensor([-0.3449, -0.3449,  0.0685,  0.0685,  0.0685,  0.2259,  1.4696,  1.4696,
     1.9946,  1.9946]),
    indices=tensor([0, 0, 2, 2, 2, 5, 6, 6, 8, 8]))

相關用法


注:本文由純淨天空篩選整理自pytorch.org大神的英文原創作品 torch.cummax。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。