Does the permute function have a bug?

1 Ansicht (letzte 30 Tage)
Zhiyong Yang
Zhiyong Yang am 5 Dez. 2019
Kommentiert: Steven Lord am 5 Dez. 2019
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!

Akzeptierte Antwort

David Goodmanson
David Goodmanson am 5 Dez. 2019
Bearbeitet: David Goodmanson am 5 Dez. 2019
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 Kommentare
Stephen23
Stephen23 am 5 Dez. 2019
"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 am 5 Dez. 2019
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

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Matrix Indexing finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by