numpy技巧
矩阵旋转:
mat_array = np.array([[1,2],[4,3]])
rotate_90 = np.zeros((2,2), np.uint8)
rotate_180 = np.zeros((2,2), np.uint8)
rotate_270 = np.zeros((2,2), np.uint8)
print(mat_array)
rotate_90[:] = mat_array[::-1].T
print(rotate_90)
rotate_180[:] = rotate_90[::-1].T
print(rotate_180)
rotate_270[:] = rotate_180[::-1].T
print(rotate_270)
原图:
[[1 2]
[4 3]]
逆时针旋转90度:
[[4 1]
[3 2]]
逆时针旋转180度:
[[3 4]
[2 1]]
逆时针旋转270度:
[[2 3]
[1 4]]
[::-1]的说明,slice的特殊用法,参考:https://www.cnblogs.com/mxh1099/p/5804064.html