且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

“变换"Numpy Array:移动维度

更新时间:2023-12-01 08:16:40

你需要的是swapaxes.

import numpy as np
a = np.zeros((3, 10, 10), np.uint8)

print(a.shape) #(3,10,10)

print(np.swapaxes(a,0,2).shape) #(10,10,3)

请参阅文档.

np.swapaxes(a,0,2) 等于 np.transpose(a, (2,1,0)).

还有一个选项是 np.transpose(a, (1,2 0)).

与往常一样,转置矩阵可以有两个版本,它们产生相似的结果,但具有不同的 3 维旋转对称性.

As always, transpose matrix can have two versions which produce similar result but with different 3-dimensional rotational symmetry.

这取决于镜像矩阵是否影响你的结果,你应该仔细测试它是否有区别.

It depends on if the mirror matrix affect your result, you should carefully test if it makes difference.