目录
np.column_stack
np.column_stack(对两个矩阵进行拼接操作)
import numpy as np
a = np.array([1,2,3,4,5])
b = np.array([6,7,8,9,10])
c = np.column_stack((a, b))
print(c)
输出结果:
[[ 1 6]
[ 2 7]
[ 3 8]
[ 4 9]
[ 5 10]]
np.arctan2
np.arctan2(求线段和x轴的夹角,单位为弧度,范围为-pi到pi)
import numpy as np
a0 = [1,1]
a1 = [1,-1]
a2 = [-1,-1]
b = [0,0]
c0 = np.arctan2(a0[1]-b[1],a0[0]-b[0])
c1 = np.arctan2(a1[1]-b[1],a1[0]-b[0])
c2 = np.arctan2(a2[1]-b[1],a2[0]-b[0])
print(c0,c1,c2)
输出结果
0.7853981633974483 -0.7853981633974483 -2.356194490192345
即45度,-45度以及-135度。
flatten()
flatten(将数组展平)
a = np.array([[1,2,3],[4,5,6]])
b = a.flatten()
c = np.array([[[1,1],[2,2],[3,3]],[[4,4],[5,5],[6,6]]])
d = c.flatten()
print(b, d)
输出结果
[1 2 3 4 5 6] [1 1 2 2 3 3 4 4 5 5 6 6]