sort()在pytorch中使用

在numpy中有 sort 和 sorted 两种,但不能对索引值排序。

# pytorch中使用
import torch
# 已知一个tensor,如,dj 是 tenor([1,3,4,2])
a , b = dj.sort(0,True)  # True是从大到小排序
# 得到的a 为 tensor([1,2,3,4])
# b 为 tensor([0,3,1,2])
# 当然,sort()括号内为空等价于 (0,False) ,即从小到大排序
Logo

汇聚全球AI编程工具,助力开发者即刻编程。

更多推荐