torch.sort 和 torch.argsort
定义
torch.sort(input,dim,descending)
torch.argsort(input,dim,descending)
用法
torch.sort:对输入数据排序,返回两个值,即排序后的数据values和其在原矩阵中的坐标indices
torch.argsort:同torch.sort()返回的indices
参数
input:输入矩阵
dim:排序维度,默认为dim=1,即对行排序
descending:排序方式(从小到大和从大到小),默认为从小到大排序(即descending=False)
示例
torch.sort()
import torch
a = torch.tensor([[2,3,1],[0,5,6]])
print(torch.sort(a))
print(torch.sort(a,dim=0))
print(torch.sort(a,dim=0,descending=True))
>>>torch.return_types.sort(
values=tensor([[1, 2, 3],
[0, 5, 6]]),
indices=tensor([[2, 0, 1],
[0, 1, 2]]))
torch.return_types.sort(
values=tensor([[0, 3, 1],
[2, 5, 6]]),
indices=tensor([[1, 0, 0],
[0, 1, 1]]))
torch.return_types.sort(
values=tensor([[2, 5, 6],
[0, 3, 1]]),
indices=tensor([[0, 1, 1],
[1, 0, 0]]))
torch.argsort()
print(torch.argsort(a))
print(torch.argsort(a,dim=0 ))
print(torch.argsort(a,dim=0,descending = False))
>>>tensor([[2, 0, 1],
[0, 1, 2]])
tensor([[1, 0, 0],
[0, 1, 1]])
tensor([[0, 1, 1],
[1, 0, 0]])
torch.sort 和 torch.argsort的更多相关文章
- 【Pytorch】关于torch.matmul和torch.bmm的输出tensor数值不一致问题
发现 对于torch.matmul和torch.bmm,都能实现对于batch的矩阵乘法: a = torch.rand((2,3,10))b = torch.rand((2,2,10))### ma ...
- [pytorch笔记] torch.nn vs torch.nn.functional; model.eval() vs torch.no_grad(); nn.Sequential() vs nn.moduleList
1. torch.nn与torch.nn.functional之间的区别和联系 https://blog.csdn.net/GZHermit/article/details/78730856 nn和n ...
- Pytorch本人疑问(1) torch.nn和torch.nn.functional之间的区别
在写代码时发现我们在定义Model时,有两种定义方法: torch.nn.Conv2d()和torch.nn.functional.conv2d() 那么这两种方法到底有什么区别呢,我们通过下述代码看 ...
- 从 relu 的多种实现来看 torch.nn 与 torch.nn.functional 的区别与联系
从 relu 的多种实现来看 torch.nn 与 torch.nn.functional 的区别与联系 relu多种实现之间的关系 relu 函数在 pytorch 中总共有 3 次出现: torc ...
- torch.rand、torch.randn、torch.normal、torch.linespace
torch.rand(*size, *, out=None, dtype=None, layout=torch.strided, device=None, requires_grad=False) # ...
- torch.cat()和torch.stack()
torch.cat() 和 torch.stack()略有不同torch.cat(tensors,dim=0,out=None)→ Tensortorch.cat()对tensors沿指定维度拼接,但 ...
- PyTorch - torch.eq、torch.ne、torch.gt、torch.lt、torch.ge、torch.le
PyTorch - torch.eq.torch.ne.torch.gt.torch.lt.torch.ge.torch.le 参考:https://flyfish.blog.csdn.net/art ...
- torch.stack()与torch.cat()
torch.stack():http://www.45fan.com/article.php?aid=1D8JGDik5G49DE1X torch.stack()个人理解:属于先变形再cat的操作,所 ...
- python sort() sorted() 与argsort()函数的区别
1.python的内建排序函数有 sort.sorted两个 sort函数只定义在list中,sorted函数对于所有的可迭代序列都可以定义. for example: ls = list([5, 2 ...
随机推荐
- sql-DQL-多表联查
多表查询 笛卡尔积 左表的每条数据和右表的每条数据组合,这种效果称为笛卡尔乘积 select * from emp, dept; 笛卡尔积引入了很多无用的数据,要完成多表查询,需要设置过滤条件来消除无 ...
- java反射之-Javabean与Map的互转
1.BeanUntils工具类的准备 /** * @ClassName: BeanUtils * @Description: * @Author: songwp * @Date: 9:02 2022/ ...
- Python程序入口 __name__ == ‘__main__‘ 有重要功能(多线程)而非编程习惯
文章来源于互联网(https://jq.qq.com/?_wv=1027&k=rX9CWKg4) 在Python中,被称为「程序的入口」的 if name =='main': 总是出现在各种示 ...
- go 编程规范
如果没有编程规范会有什么问题? 哪些地方可以需要指定规范? 非编码类规范:编码规范 非编码规范 开源规范 http://www.ruanyifeng.com/blog/2011/05/how_to_c ...
- AOP-动态代理
动态代理的原理代理设计模式的原理:使用一个代理将原本对象包装起来,然后用该代理对象"取代"原始对象.任何对原始对象的调用都要通过代理.代理对象决定是否以及何时将方法调用转到原始对象 ...
- 如何用天气预警API接口进行快速开发
天气预警能够指导人们出行.同一种类的气象灾害预警信号级别不同,对应的防御措施也不尽相同,人们通过气象灾害预警信号,合理安排出行.公众要提高防范意识,养成接收和关注预警信息的习惯,了解预警信息背后的意义 ...
- 【C++】从设计原理来看string类
1.一些C++基础知识 模板类string的设计属于底层,其中运用到了很多C++的编程技巧,比如模板.迭代器.友元.函数和运算符重载.内联等等,为了便于后续理解string类,这里先对涉及到的概念做个 ...
- JUC源码学习笔记3——AQS等待队列和CyclicBarrier,BlockingQueue
一丶Condition 1.概述 任何一个java对象都拥有一组定义在Object中的监视器方法--wait(),wait(long timeout),notify(),和notifyAll()方法, ...
- zabbix 6.2.0部署
zabbix 6.2官方部署文档 https://www.zabbix.com/documentation/6.2/en/manual/installation/install下载zabbix6.2安 ...
- Linux ssh协议
基础知识 ssh:secure shell protocol,安全的远程登录 作用:是建立在应用层基础上的安全协议,实现数据传输过程中数据的加密,代替telent协议 使用tcp协议,端口号为22 s ...