PyTorch torch.argsort 関数


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

torch.argsortPyTorch において、ソート後のインデックスを返すための関数です。テンソルをソートした後の各要素の元の位置のインデックスを返します。

関数定義

torch.argsort(input, dim=-1, descending=False, stable=True)

使用例

実例

import torch

# テンソルを作成
x = torch.tensor([3, 1, 2])

# ソート後のインデックスを返す
indices = torch.argsort(x)
print(indices)

出力結果は次のとおりです:

tensor([1, 2, 0])

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

その他の拡張