PyTorch torch.sort 関数


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

torch.sortは PyTorch において、指定された次元に沿ってソートするための関数です。

関数定義

torch.sort(input, dim, descending, stable, out)

使用例

実例

import torch

x = torch.tensor([[3, 1, 2], [6, 4, 5]])

# ソート
values, indices = torch.sort(x)

print("ソート値:")
print(values)
print("ソートインデックス:")
print(indices)

# 降順ソート
values_desc, _ = torch.sort(x, descending=True)
print("降順:")
print(values_desc)

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

その他の拡張