Related Articles
numpy.unwrap() in Python
• Last Updated : 06 Jan, 2019

`numpy.unwrap(p, discont=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 discont to their 2*pi complement along the given axis. Result is an unwraped array.

Parameters:

p : [array like] input array
discont : [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 discont, no unwrapping is done because taking the 2*pi complement would only make the discontinuity larger.

Code #1: Default Values Working
 `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, discont > 2*pi (between 0.78 and 5.49), so array values are changed.

Code #2: Custom Values Working

 `import` `numpy as np`` ` `l1 ``=``[``5``, ``7``, ``10``, ``14``, ``19``, ``25``, ``32``]``print``(``"Result 1: "``, np.unwrap(l1, discont ``=` `4``))`` ` `l2 ``=``[``0``, ``1.34237486723``, ``4.3453455``, ``8.134654756``, ``9.3465456542``]``print``(``"Result 2: "``, np.unwrap(l2, discont ``=` `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]

Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.

To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course. And to begin with your Machine Learning Journey, join the Machine Learning – Basic Level Course

My Personal Notes arrow_drop_up