필터 지우기
필터 지우기

Does the permute function have a bug?

조회 수: 3 (최근 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 CenterFile Exchange에서 Matrix Indexing에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by