标签:details 格式 ora ISE nbsp array 不同 weixin div
从NumPy的官方完整查到rot90函数语法格式如下:
rot90(m, k=1, axes=(0, 1)
m是要旋转的数组(矩阵),k是旋转的次数,默认旋转1次,那是顺时针还是逆时针呢?正数表示逆时针,而k为负数时则是对数组进行顺时针方向的旋转。axes是由坐标轴定义的平面,旋转轴垂直于该平面,坐标轴必须不同,用于三维矩阵的旋转。
import numpy as np mat = np.array([[1,3,5], [2,4,6], [7,8,9] ]) print mat, "# orignal" mat90 = np.rot90(mat, 1) print mat90, "# rorate 90 <left> anti-clockwise" mat90 = np.rot90(mat, -1) print mat90, "# rorate 90 <right> clockwise" mat180 = np.rot90(mat, 2) print mat180, "# rorate 180 <left> anti-clockwise" mat270 = np.rot90(mat, 3) print mat270, "# rorate 270 <left> anti-clockwise"
执行结果:
[[1 3 5] [2 4 6] [7 8 9]] # orignal [[5 6 9] [3 4 8] [1 2 7]] # rorate 90 <left> anti-clockwise [[7 2 1] [8 4 3] [9 6 5]] # rorate 90 <right> clockwise [[9 8 7] [6 4 2] [5 3 1]] # rorate 180 <left> anti-clockwise [[7 2 1] [8 4 3] [9 6 5]] # rorate 270 <left> anti-clockwise
三维矩阵围绕Z轴旋转:
import numpy as np if __name__ == ‘__main__‘: weights = np.array( [[[-1, 1, 0], [0, 1, 0], [0, 1, 1]], [[-1, -1, 0], [0, 0, 0], [0, -1, 0]], [[0, 0, -1], [0, 1, 0], [1, -1, -1]]], dtype=np.float64) flipped_weights = np.rot90(weights, 2 , (1,2)) print(flipped_weights)
执行结果:
[[[ 1. 1. 0.] [ 0. 1. 0.] [ 0. 1. -1.]] [[ 0. -1. 0.] [ 0. 0. 0.] [ 0. -1. -1.]] [[-1. -1. 1.] [ 0. 1. 0.] [-1. 0. 0.]]]
参考:
http://liao.cpython.org/numpy13/
https://blog.csdn.net/weixin_39506322/article/details/89463286
标签:details 格式 ora ISE nbsp array 不同 weixin div
原文地址:https://www.cnblogs.com/ratels/p/12310493.html