给定numpy中的3d矩阵,如何将矩阵A转换为矩阵B,然后将B转置回A。
我似乎能够将A转换为矩阵:
>>> import numpy
>>> a = numpy.random.rand(3,3,3)
>>> print a
[[[ 0.69774026 0.14510969 0.12476703]
[ 0.02631041 0.61497379 0.86985018]
[ 0.14114129 0.87731903 0.76020481]]
[[ 0.66507441 0.16093391 0.19799549]
[ 0.56614043 0.17268869 0.39641231]
[ 0.61712168 0.71372674 0.32510021]]
[[ 0.50997888 0.75687504 0.69902029]
[ 0.50366012 0.22187467 0.58894526]
[ 0.8726912 0.4319045 0.43687999]]]
>>> b = a.transpose(0,2,1)
>>> print b
[[[ 0.69774026 0.02631041 0.14114129]
[ 0.14510969 0.61497379 0.87731903]
[ 0.12476703 0.86985018 0.76020481]]
[[ 0.66507441 0.56614043 0.61712168]
[ 0.16093391 0.17268869 0.71372674]
[ 0.19799549 0.39641231 0.32510021]]
[[ 0.50997888 0.50366012 0.8726912 ]
[ 0.75687504 0.22187467 0.4319045 ]
[ 0.69902029 0.58894526 0.43687999]]]
但是我如何将矩阵b返回到矩阵a?