我想旋轉數組但不像基本矩陣旋轉。如果我有一個3x3陣列,我希望每個單元都圍繞中心單元轉動。在中央單元周圍旋轉3x3陣列的每個單元的模塊(不是矩陣旋轉)
這裏是一個3x3陣列:
import numpy as np
tab = np.array([[1,2,3],[4,5,6],[7,8,9]])
[[1 2 3]
[4 5 6]
[7 8 9]]
我想例如通過旋轉45度吧:
[[2 3 6]
[1 5 9]
[4 7 8]]
我不能使用scipy.ndimage.interpolation.rotate(tab,45)
因爲它適用於基本矩陣的旋轉,這不是我想要的。
import numpy as np
from scipy import ndimage
tab = np.array([[1,2,3],[4,5,6],[7,8,9]])
ndimage.interpolation.rotate(tab,45)
[[0 0 0 0]
[0 2 6 0]
[0 4 8 0]
[0 0 0 0]]
有沒有人知道這是如何實現的?
太棒了,謝謝你的解釋。 –
這可能不會對大於3x3的矩陣做正確的事 – Eric