I have a 3d array created with numpy, and I was wondering how I can rotate it by a custom angle, not just the rot90
function that numpy has. Can anyone help?
The 3d matrix represents an image (such as a cube, or some other shape) ie
0:
1 1 1
1 1
1 1 1
1:
1 1
1 1
2:
1 1 1
1 1
1 1 1
EDIT: Moved solution to answer
Have a look at the scipy.ndimage.interpolation.rotate function.
The reason this is in scipy and not in numpy is that rotating an image 90 degrees is done by just chaning the indices of the array. However, if you want to rotate an image by some arbitrary degrees you have to deal with interpolation, which adds a whole new layer of complexity to the problem. This is because all the pixels in the original image "perfectly lines up with" pixels in the rotated image when you rotate it by a factor of 90 degrees. This is not the case in general when you rotate an image.