PyTorch torch.cummin 関数


Pytorch torch 参考手册Pytorch torch リファレンスマニュアル

torch.cumminこれは PyTorch で累積最小値を計算するための関数です。指定された次元に沿った累積最小値と対応するインデックスを返します。

関数定義

torch.cummin(input, dim, dtype=None)

使用例

実例

import torch

# 累積最小値を計算
x = torch.tensor([3, 1, 4, 1, 5, 9, 2, 6])
values, indices = torch.cummin(x, dim=0)
print("入力:", x)
print("累積最小値:", values)
print("最小値インデックス:", indices)

# 2次元テンソル
x = torch.tensor([[3, 1, 4], [1, 5, 9], [2, 6, 5]], dtype=torch.float32)
# 列ごとに累積
values_col, indices_col = torch.cummin(x, dim=0)
print("n列ごとの累積:")
print("累積最小値:")
print(values_col)
print("インデックス:")
print(indices_col)

# 行ごとに累積
values_row, indices_row = torch.cummin(x, dim=1)
print("n行ごとの累積:")
print("累積最小値:")
print(values_row)

Pytorch torch 参考手册Pytorch torch リファレンスマニュアル

その他の拡張