1 先看看官方中英文doc:
1.1 permute(dims)
This is choosing `4` from `5` (any `4` digit number chosen from `3, 4, 6, 8, 9` will be ` 1000`) plus `5` from `5` (any `5` digit number will be ` 1000`), where order is important. So the number of ways we can arrange the given digits so that our resulting number is greater than `1000` such that no digit occurs more than once, is.
将tensor的维度换位。
- Permutation Problem 1. Choose 3 horses from group of 4 horses. In a race of 15 horses you beleive that you know the best 4 horses and that 3 of them will finish.
- Therefore, the total number of ways they can be next to each other is 2 5! Permutations of less than all. We have seen that the number of ways of choosing 2 letters from 4 is 4 3 = 12. We call this 'The number of permutations of 4 different things taken 2 at a time.' We will symbolize this as 4 P 2: 4 P 2 = 4 3.
- Permute for Mac 2.4.5 介绍. Permute for Mac是最容易使用的媒体转换器,它很容易使用,无需配置,你只需将文件拖放进界面窗口,它将满足的需求,对所有的媒体进行转换。 使用方便. 快速建立媒体转换任务,Permute for Mac很好的诠释了苹果应用程序的实用和优秀。.
参数: - __dims__ (int .*) - 换位顺序 Disk doctor 4 0 – free up disk space. Clearview 1 7 3 download free.
例:
1.2 permute(*dims) → Tensor
![Permute Permute](https://content.wolfram.com/uploads/sites/35/2011/11/permutations-image8.jpg)
Permute the dimensions of this tensor.
Parameters: *dims (int..) – The desired ordering of dimensions
Example:
2 pytorch permute的使用
permute函数功能还是比较简单的,下面主要介绍几个细节点:
2.1 transpose与permute的异同
Tensor.permute(a,b,c,d, ..):permute函数可以对任意高维矩阵进行转置,但没有 torch.permute() 这个调用方式, 只能 Tensor.permute():
![Permute Permute](https://upload.wikimedia.org/wikipedia/commons/thumb/e/e1/3-ary_Boolean_functions%3B_cube_permutations%3B_4.svg/500px-3-ary_Boolean_functions%3B_cube_permutations%3B_4.svg.png)
torch.transpose(Tensor, a,b):transpose只能操作2D矩阵的转置,有两种调用方式;
另:连续使用transpose也可实现permute的效果:
从以上操作中可知,permute相当于可以同时操作于tensor的若干维度,transpose只能同时作用于tensor的两个维度; Outline 3 21 4 – view onenote notebooks pdf.
2.2 permute函数与contiguous、view函数之关联
contiguous:view只能作用在contiguous的variable上,如果在view之前调用了transpose、permute等,就需要调用contiguous()来返回一个contiguous copy;
一种可能的解释是:有些tensor并不是占用一整块内存,而是由不同的数据块组成,而tensor的view()操作依赖于内存是整块的,这时只需要执行contiguous()这个函数,把tensor变成在内存中连续分布的形式;
判断ternsor是否为contiguous,可以调用torch.Tensor.is_contiguous()函数:
另:在pytorch的最新版本0.4版本中,增加了torch.reshape(),与 numpy.reshape() 的功能类似,大致相当于 tensor.contiguous().view(),这样就省去了对tensor做view()变换前,调用contiguous()的麻烦;
3 permute与view函数功能demo
利用函数 permute(2,0,1) 可以把 Tensor([[[1,2,3],[4,5,6]]]) 转换成:
如果使用view(1,3,2) 可以得到:
Permute 2 2 4 5 And 1 8 Over The X Axis
5 参考
5 Permute 2
发布于 2019-08-09