Effacer les filtres
Effacer les filtres

Does the permute function have a bug?

3 vues (au cours des 30 derniers jours)
Zhiyong Yang
Zhiyong Yang le 5 Déc 2019
Commenté : Steven Lord le 5 Déc 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!

Réponse acceptée

David Goodmanson
David Goodmanson le 5 Déc 2019
Modifié(e) : David Goodmanson le 5 Déc 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 commentaires
Stephen23
Stephen23 le 5 Déc 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 le 5 Déc 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

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Matrix Indexing dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by