numpy.unwrap(p, discount=3.141592653589793, axis=-1) function helps user to unwrap a given array by changing deltas to values of 2*pi complement. It unwraps radian phase p by changing absolute jumps greater than discount to their 2*pi complement along the given axis. Result is an unwrapped array.
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
Note: If the discontinuity in p is smaller than pi, but larger than discount, no unwrapping is done because taking the 2*pi complement would only make the discontinuity larger.
Code #1: Default Values Working
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)) |
Output:
Result 1: array([1., 2., 3., 4., 5.]) Result 2: array([ 0., 0.78, -0.79318531, -0.00318531])
In l2, discount > 2*pi (between 0.78 and 5.49), so array values are changed.
Code #2: Custom Values Working
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 )) |
Output:
Result 1: [ 5., 7., 10., 7.71681469, 6.43362939, 6.15044408, 6.86725877]
Result 2: [0., 1.34237487, 4.3453455, 1.85146945, 3.06336035]
References: https://docs.scipy.org/doc/numpy-1.15.1/reference/generated/numpy.unwrap.html