Matlab中的置换功能如何工作 [英] How does the permute function in matlab work

查看:111
本文介绍了Matlab中的置换功能如何工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是一个有点愚蠢的问题,但我似乎无法弄清楚如何在matlab中进行置换.以文档示例为例:

This is a somewhat silly question but I can't seem to figure out how permute works in matlab. Take the documentation example:

A = [1 2; 3 4]; permute(A,[2 1])
ans =
 1     3
 2     4

这是怎么回事?这如何告诉Matlab 3和2需要交换?

What is going on? How does this tell matlab that the 3 and 2 need to be swapped?

推荐答案

permute对数组的尺寸进行排列,而不是对数组元素的排列,正如人们可能希望从其名称中得出的那样.

permute does a permutation of the dimensions of an array, not of its elements, as one may expect from its name.

因此,permute(A,[2,1])将数组A的维度2(列)与数组A的维度1(行)翻转,这等效于转置(A').

Thus, permute(A,[2,1]) flips dimension 2 (the columns) of array A with dimension 1 (the rows) of array A, which is equivalent to a transpose (A').

permute(A,[3,2,1])将产生一个1×2×2数组(因为size(A,3)==1),其中该数组水平翻转".

permute(A,[3,2,1]) would produce a 1-by-2-by-2 array (because size(A,3)==1), where the array is "flipped up horizontally".

这篇关于Matlab中的置换功能如何工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆