Does the permute function have a bug?

2 ビュー (過去 30 日間)
Zhiyong Yang
Zhiyong Yang 2019 年 12 月 5 日
コメント済み: Steven Lord 2019 年 12 月 5 日
Hi, when i use the permute function to shift dimensions of a four-dimension array, it has:
K>> U=randn(2,300,150,1000); U=permute(U,[4 1 2 3]); size(U)
ans =
1000 2 300 150
Why it doesnot shift the first dimension to forth dimension. Am i wrong or it is the issue of permute function. The matlab version is R2019b. Thanks!

採用された回答

David Goodmanson
David Goodmanson 2019 年 12 月 5 日
編集済み: David Goodmanson 2019 年 12 月 5 日
Hello ZY,
see 'help permute'. Permute puts the dimensions in the order listed, so in this case the old 4th dimension goes first, old first dimension goes second, etc.
It could have been that each dimension goes to the dimension specified in its original slot, so that the first dimension goes fourth, the second dimension goes first. etc. That is a legit and consistent way of doing things, but it's not how it was done.
  2 件のコメント
Stephen23
Stephen23 2019 年 12 月 5 日
"Permute puts the dimensions in the order listed"
Just like indexing, which is interpreted in the same way: elements (or rows/columns/pages/...) are put into the order listed by the index. So permute is perfectly consistent with this.
Steven Lord
Steven Lord 2019 年 12 月 5 日
Not only is that alternate interpretation a "legit and consistent way of doing things", it is the way that ipermute works. Showing this with a slightly smaller array:
>> U = ones(2, 3, 4, 5);
>> v = [4 1 2 3];
>> size(U)
ans =
2 3 4 5
>> size(permute(U, v))
ans =
5 2 3 4
>> size(ipermute(U, v))
ans =
3 4 5 2

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeMatrix Indexing についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by