Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags

python
python3
numpy

How to use numpy.unwrap() function in Python

Maria Elijah

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 is pi.
  • axis: This parameter is an integer type, and it’s optional. It represents the axis along which the unwrap() function is to be performed. The default value is the last axis.
  • period: This parameter is float type, and it’s optional. It represents the size of the input wrap range. The default value is 2 pi.

Example

# import numpy
import numpy as np
# create a list
my_list = [24,8,3,4,34,8]
# convert the list to numpy array
np_list = np.array(my_list)
print(f"Original array before the np.unwrap(): {np_list}")
# unwrap each element and store it
np_list_unwrap = np.unwrap(np_list)
print("After the np.unwrap()")
print(np_list_unwrap)
Using the numpy.unwrap() function

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 to 2*pi complement values.
  • Line 10–11: We display the result.

RELATED TAGS

python
python3
numpy
RELATED COURSES

View all Courses

Keep Exploring