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 ...
随机推荐
- Linux安装fastdfs集群部署
过程问题: make: gcc:命令未找到 解决: yum -y install gcc 一.环境和版本: Linux环境:CentOS 7.6 libfastcommon版本:1.0.39 Fast ...
- IDEA插件配置之Eclipse Code Formatte
1.下载 在idea中的Plugins中下载插件 Eclipse Code Formatte,下载过之后重启. 2.配置 将自己下载的xml文件加载进来即可. 这个xml文件可自行在网上找找,有需要的 ...
- ubuntu20.04安装测试uhttpd
uhttpd是openwrt上运行一个高效小型Http服务,支持cgi, lua等特性.可以直接通过snap方式安装,如果是16.04,18.04或者20.04,snap已经默认安装了:如果是其它版本 ...
- springboot creating bean with name 'sqlSessionFactory'
pom.xml文件配置 <build> <plugins> <plugin> <groupId>org.springframework.boot< ...
- IIS部署的H5的单页面跳转的配置
<?xml version="1.0" encoding="UTF-8"?><configuration> <system.web ...
- OpenMP入门
OpenMP入门 前情提要:并行(parallel):需要多个运算核心同时完成 其中有多处理器和单处理器多核两种实现方式,其中差异如下: 同一芯片上的多核通信速度更快 同一芯片上的多核能耗更低 Ope ...
- Java---注解与反射
前言 近期在学习SSM框架的过程中发现在SSM框架中大量用到了反射与注解的知识,要想学好SSM框架,必须将注解与反射熟记于心,尤其是对Java反射机制的理解. 对于我这种记性不好的人来说"基 ...
- C#枚举器/迭代器
一.枚举器 1.为什么foreach可以顺序遍历数组? 因为foreach可以识别可枚举类型,通过访问数组提供的枚举器对象来识别数组中元素的位置从而获取元素的值并打印出来. 2.什么是枚举器?可枚举类 ...
- ahooks 是怎么解决用户多次提交问题?
本文是深入浅出 ahooks 源码系列文章的第四篇,该系列已整理成文档-地址.觉得还不错,给个 star 支持一下哈,Thanks. 本文来探索一下 ahooks 的 useLockFn.并由此讨论一 ...
- thinkphp 5 及一下或php项目里实现模糊查询
想在thinkPHP或者PHP项目实现模糊查询怎么实现呢? 今天在网上搜了一下用 mysql里的 like 就可以实现 怎么用呢? 看代码: 错误用法: where('title','like',$s ...