博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Pytorch数组反转(数组倒序)函数flip的使用
阅读量:3564 次
发布时间:2019-05-20

本文共 971 字,大约阅读时间需要 3 分钟。

torch.flip(input, dims) → Tensor

Reverse the order of a n-D tensor along given axis in dims.
对n维张量的指定维度进行反转(倒序)


NOTE

torch.flip makes a copy of input’s data. This is different from NumPy’s np.flip, which returns a view in constant time. Since copying a tensor’s data is more work than viewing that data, torch.flip is expected to be slower than np.flip.

注意torch.flip是反序地复制一份新的数据,这一点与NumPy不同,NumPy是返回一个view,因而使用torch.flip耗时更久。


Parameters

  • input (Tensor) – the input tensor.
  • dims (a list or tuple) – axis to flip on

Example:

>>> x = torch.arange(10).view(2, 5)>>> xtensor([[0, 1, 2, 3, 4],        [5, 6, 7, 8, 9]])>>> torch.flip(x, dims=[0])	# 对第0维进行反转tensor([[5, 6, 7, 8, 9],        [0, 1, 2, 3, 4]])>>> torch.flip(x, dims=[1])	# 对第1维进行反转tensor([[4, 3, 2, 1, 0],        [9, 8, 7, 6, 5]])>>> torch.flip(x, dims=[0, 1])	# 对第0、1维进行反转tensor([[9, 8, 7, 6, 5],        [4, 3, 2, 1, 0]])>>> x.flip(dims=[0, 1])	# 对第0、1维进行反转,与上一句效果相同tensor([[9, 8, 7, 6, 5],        [4, 3, 2, 1, 0]])

转载地址:http://thvrj.baihongyu.com/

你可能感兴趣的文章
[HDU] 平方和与立方和
查看>>
[HDU 2096] 小明A+B
查看>>
[HDU 2520] 我是菜鸟,我怕谁(不一样的for循环)
查看>>
[HDU 1215] 七夕节(求因子,不超时)
查看>>
[POJ 1915] Knight Moves
查看>>
Memcache技术精华
查看>>
Redis详解入门篇
查看>>
php开启redis扩展包与redis安装
查看>>
php使用openssl来实现非对称加密
查看>>
pdo如何防止 sql注入
查看>>
myisam和innodb的区别
查看>>
MySQL建表规范与注意事项(个人精华)
查看>>
JDK8接口的新特性
查看>>
synchronized的局限性与lock的好处
查看>>
redis和memcached有什么区别?
查看>>
Spring中的设计模式
查看>>
如何设计一个秒杀系统 -- 架构原则
查看>>
如何设计一个秒杀系统 -- 动静分离方案
查看>>
JWT 快速了解
查看>>
实习日志一
查看>>