Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/354.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 将3d矩阵变换两次?_Python_Numpy_Matrix - Fatal编程技术网

Python 将3d矩阵变换两次?

Python 将3d矩阵变换两次?,python,numpy,matrix,Python,Numpy,Matrix,给定numpy中的3d矩阵,如何将矩阵a转换为矩阵B,然后将B转换回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.76

给定numpy中的3d矩阵,如何将矩阵a转换为矩阵B,然后将B转换回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?

转置(transpose(a))=a,所以。。。再换一次?是的。。但是,需要将哪个轴放置在转置后与先前轴匹配的位置。。b、 T将只转置2d数组,这就是为什么我使用b.transpose(..),但轴的位置欺骗了我…
b.transpose(0,2,1)
谢谢@Psidom。。我想我并不像我想的那么复杂。。。