赞
踩
- x=
- [[[ 1 2 3 4]
- [ 5 6 7 8]]
-
- [[ 9 10 11 12]
- [13 14 15 16]]]
对x进行transpose((2,1,0))处理思路如下:
1.写出x的所有索引号
x[0][0][0] == 1;x[0][0][1] == 2;x[0][0][2] == 3;x[0][0][3] == 4;
x[0][1][0] == 5;x[0][1][1] == 6;x[0][1][2] == 7;x[0][1][3] == 8;
x[1][0][0] == 9;x[1][0][1] == 10;x[1][0][2] == 11;x[1][0][3] == 12;
x[1][1][0] == 13;x[1][1][1] == 14;x[1][1][2] == 15;x[1][1][3] == 16;
2.transpose((2,1,0))可以看成(0,1,2)—>(2,1,0),即x索引号中交换第一维与第三维,得到以下结果
x[0][0][0] == 1;x[1][0][0] == 2;x[2][0][0] == 3;x[3][0][0] == 4;
x[0][1][0] == 5;x[1][1][0] == 6;x[2][1][0] == 7;x[3][1][0] == 8;
x[0][0][1] == 9;x[1][0][1] == 10;x[2][0][1] == 11;x[3][0][1] == 12;
x[0][1][1] == 13;x[1][1][1] == 14;x[2][1][1] == 15;x[3][1][1] == 16;
调整后得到以下结果
x[0][0][0] == 1;x[0][0][1] == 9;x[0][1][0] == 5;x[0][1][1] == 13;
x[1][0][0] == 2;x[1][0][1] == 10;x[1][1][0] == 6;x[1][1][1] == 14;
x[2][0][0] == 3;x[2][0][1] == 11;x[2][1][0] == 7;x[2][1][1] == 15
;x[3][0][0] == 4;x[3][0][1] == 12;x[3][1][0] == 8;x[3][1][1] == 16;
3.故对x进行transpose((2,1,0))处理后得到以下结果
- x.transpose((2,1,0))=
- [
- [[ 1 9 ]
- [ 5 13]]
- [[ 2 10 ]
- [ 6 14 ]]
- [[ 3 11 ]
- [ 7 15]]
- [[ 4 12 ]
- [ 8 16 ]]
- ]
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。