How to use numpy.unwrap() function in Python
The numpy.unwrap() function
The numpy.unwrap() function is a numpy’s function used to unwrap a given array by transforming deltas to 2*pi complement values.
This function unwraps the radian phase, p (arr), along the supplied axis by converting absolute leaps greater than a discount to their 2*pi complement.
Syntax
numpy. unwrap ( p,
discount=None,
axis=- 1,
*,
period=6.283185307179586 )
Parameters
p: it represents the specified array.discount: Th parameter is an optional float type. It represents the maximum discontinuity between values. The default value ispi.axis: This parameter is an integer type, and it’s optional. It represents the axis along which theunwrap()function is to be performed. The default value is the lastaxis.period: This parameter is float type, and it’s optional. It represents the size of the input wrap range. The default value is2 pi.
Example
# import numpyimport numpy as np# create a listmy_list = [24,8,3,4,34,8]# convert the list to numpy arraynp_list = np.array(my_list)print(f"Original array before the np.unwrap(): {np_list}")# unwrap each element and store itnp_list_unwrap = np.unwrap(np_list)print("After the np.unwrap()")print(np_list_unwrap)
Explanation
- Line 2: We import the library
numpy. - Line 4: We create a list called
my_list. - Line 6: We convert the list to a NumPy array and store it in a variable named
np_list. - Line 7: We display elements in
np_list. - Line 8: We use the
np.unwrap()to unwrap the given array,np_list, by converting it to2*picomplement values. - Line 10–11: We display the result.