定义

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的更多相关文章

  1. 【Pytorch】关于torch.matmul和torch.bmm的输出tensor数值不一致问题

    发现 对于torch.matmul和torch.bmm,都能实现对于batch的矩阵乘法: a = torch.rand((2,3,10))b = torch.rand((2,2,10))### ma ...

  2. [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 ...

  3. Pytorch本人疑问(1) torch.nn和torch.nn.functional之间的区别

    在写代码时发现我们在定义Model时,有两种定义方法: torch.nn.Conv2d()和torch.nn.functional.conv2d() 那么这两种方法到底有什么区别呢,我们通过下述代码看 ...

  4. 从 relu 的多种实现来看 torch.nn 与 torch.nn.functional 的区别与联系

    从 relu 的多种实现来看 torch.nn 与 torch.nn.functional 的区别与联系 relu多种实现之间的关系 relu 函数在 pytorch 中总共有 3 次出现: torc ...

  5. torch.rand、torch.randn、torch.normal、torch.linespace

    torch.rand(*size, *, out=None, dtype=None, layout=torch.strided, device=None, requires_grad=False) # ...

  6. torch.cat()和torch.stack()

    torch.cat() 和 torch.stack()略有不同torch.cat(tensors,dim=0,out=None)→ Tensortorch.cat()对tensors沿指定维度拼接,但 ...

  7. 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 ...

  8. torch.stack()与torch.cat()

    torch.stack():http://www.45fan.com/article.php?aid=1D8JGDik5G49DE1X torch.stack()个人理解:属于先变形再cat的操作,所 ...

  9. python sort() sorted() 与argsort()函数的区别

    1.python的内建排序函数有 sort.sorted两个 sort函数只定义在list中,sorted函数对于所有的可迭代序列都可以定义. for example: ls = list([5, 2 ...

随机推荐

  1. word processing in nlp with tensorflow

    Preprocessing Tokenizer source code:https://github.com/keras-team/keras-preprocessing/blob/master/ke ...

  2. lerna源码阅读

    能够找到入口文件 能够本地调试

  3. Nginx越界读取缓存漏洞 CVE-2017-7529

    1.漏洞描述 Nginx在反向代理站点的时候,通常会将一些文件进行缓存,特别是静态文件.缓存的部分存储在文件中,每个缓存文件包括"文件头"+"HTTP返回包头" ...

  4. 分布式事务(Seata)原理 详解篇,建议收藏

    前言 在之前的系列中,我们讲解了关于Seata基本介绍和实际应用,今天带来的这篇,就给大家分析一下Seata的源码是如何一步一步实现的.读源码的时候我们需要俯瞰起全貌,不要去扣一个一个的细节,这样我们 ...

  5. HMS Core音频编辑服务支持7种音频特效,助力一站式音频处理

    多媒体时代,音频作为内容传播中的重要形式,因其不受空间限制.认知负担小.声音元素多样化等特点,广泛应用于短视频制作.儿童在线教育.有声阅读.游戏等领域产品,在各种形式的音频呈现过程中,合理添加音效能够 ...

  6. Docker安装NextCloud使用MySQL

    安装 1.拉取并启动MySQL,最好把数据可目录挂载到宿主机,以便容器被误删后恢复: docker run --name=nextcloud_db \ -e MYSQL_ROOT_PASSWORD=X ...

  7. 多重分派(multiple dispatch)与访问者模式

    什么是双重分派 什么是分派(dispatch) 首先我们需要理解「分派」的含义.分派就是将方法调用与对应的具体方法绑定起来.而判断的依据有两点,这两者可称为「宗量」: 方法的接收者,也就是哪个对象调用 ...

  8. Note -「数论 定理及结论整合」

    数学素养 low,表达可能存在不严谨,见谅.我准备慢慢补上证明? Theorems. 裴蜀定理:关于 \(x, y\) 的线性方程 \(ax + by = c\) 有解,当且仅当 \(\gcd (a, ...

  9. CF1703E Mirror Grid 题解

    给定一个矩阵,判断最少将多少个格反转后使得旋转零度,九十度,一百八十度,二百七十度相等. 枚举矩阵每个位置是 \(0\) 还是 \(1\),若已经判断过则跳过,全统 \(1\) 和全统 \(0\) 取 ...

  10. Android开启OTG功能/USB Host API功能

    Android USB 模式简介 设备模式 当计算机或其他USB主机需要连接安卓设备时,此时安卓设备是作为"USB设备"角色的,在计算机上显示为 USB 外设.现在的安卓设备已经被 ...