KimHee KimHee -4 years ago 185
Python Question

How to rotate a 3D matrix along X,Y, or Z axial plane?

I have a 3D matrix with size DxHxW. I want to rotate it 90 degrees along the (1) X-axis, (2) Y-axis and (3) Z-axis. I just completed Y-axis. How can I do it with X and Z-axis? I am using python 2.7. Thanks all


Answer Source

numpy.rot90 has an axes argument. You can use it to rotate about all tree axes,

m = np.arange(8).reshape((2,2,2))
m1 = np.rot90(m, axes=(0,1))
m2 = np.rot90(m, axes=(1,2))
m3 = np.rot90(m, axes=(0,2))

(Since it's not clear what x,y,z axis are from the question, you need to decide for yourself, which one you need)

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download