Python中的 numpy.unwrap()
numpy.unwrap(p, discount=3.141592653589793, axis=-1)函数通过将增量更改为 2*pi 补码的值来帮助用户解包给定数组。它通过沿给定轴改变绝对跳跃大于折扣到它们的 2*pi 补码来展开弧度相位p 。结果是一个未包装的数组。
Parameters:
p : [array like] input array
discount : [float, optional] Maximum discontinuity between values, default is pi
axis : [int, optional] Axis along which unwrap will operate, default is last axis
Returns: [ndarray] output array
注意:如果 p 中的不连续性小于pi但大于折扣,则不进行展开,因为取 2*pi 补码只会使不连续性变大。
代码 #1:默认值工作
Python3
import numpy as np
l1 =[1, 2, 3, 4, 5]
print("Result 1: ", np.unwrap(l1))
l2 =[0, 0.78, 5.49, 6.28]
print("Result 2: ", np.unwrap(l2))
Python3
import numpy as np
l1 =[5, 7, 10, 14, 19, 25, 32]
print("Result 1: ", np.unwrap(l1, discount = 4))
l2 =[0, 1.34237486723, 4.3453455, 8.134654756, 9.3465456542]
print("Result 2: ", np.unwrap(l2, discount = 3.1))
输出:
Result 1: array([1., 2., 3., 4., 5.])
Result 2: array([ 0., 0.78, -0.79318531, -0.00318531])
在 l2 中,折扣 > 2*pi(介于 0.78 和 5.49 之间),因此数组值发生了变化。
代码 #2:自定义值有效
Python3
import numpy as np
l1 =[5, 7, 10, 14, 19, 25, 32]
print("Result 1: ", np.unwrap(l1, discount = 4))
l2 =[0, 1.34237486723, 4.3453455, 8.134654756, 9.3465456542]
print("Result 2: ", np.unwrap(l2, discount = 3.1))
输出:
Result 1: [ 5., 7., 10., 7.71681469, 6.43362939, 6.15044408, 6.86725877]
Result 2: [0., 1.34237487, 4.3453455, 1.85146945, 3.06336035]
参考资料: https://docs.scipy.org/doc/numpy-1.15.1/reference/generated/numpy.unwrap.html