MCPcopy Index your code
hub / github.com/numpy/numpy / unwrap

Function unwrap

numpy/lib/_function_base_impl.py:1752–1863  ·  view source on GitHub ↗

r""" Unwrap by taking the complement of large deltas with respect to the period. This unwraps a signal `p` by changing elements which have an absolute difference from their predecessor of more than ``max(discont, period/2)`` to their `period`-complementary values. For the defau

(p, discont=None, axis=-1, *, period=2 * pi)

Source from the content-addressed store, hash-verified

1750
1751@array_function_dispatch(_unwrap_dispatcher)
1752def unwrap(p, discont=None, axis=-1, *, period=2 * pi):
1753 r"""
1754 Unwrap by taking the complement of large deltas with respect to the period.
1755
1756 This unwraps a signal `p` by changing elements which have an absolute
1757 difference from their predecessor of more than ``max(discont, period/2)``
1758 to their `period`-complementary values.
1759
1760 For the default case where `period` is :math:`2\pi` and `discont` is
1761 :math:`\pi`, this unwraps a radian phase `p` such that adjacent differences
1762 are never greater than :math:`\pi` by adding :math:`2k\pi` for some
1763 integer :math:`k`.
1764
1765 Parameters
1766 ----------
1767 p : array_like
1768 Input array.
1769 discont : float, optional
1770 Maximum discontinuity between values, default is ``period/2``.
1771 Values below ``period/2`` are treated as if they were ``period/2``.
1772 To have an effect different from the default, `discont` should be
1773 larger than ``period/2``.
1774 axis : int, optional
1775 Axis along which unwrap will operate, default is the last axis.
1776 period : float, optional
1777 Size of the range over which the input wraps. By default, it is
1778 ``2 pi``.
1779
1780 .. versionadded:: 1.21.0
1781
1782 Returns
1783 -------
1784 out : ndarray
1785 Output array.
1786
1787 See Also
1788 --------
1789 rad2deg, deg2rad
1790
1791 Notes
1792 -----
1793 If the discontinuity in `p` is smaller than ``period/2``,
1794 but larger than `discont`, no unwrapping is done because taking
1795 the complement would only make the discontinuity larger.
1796
1797 Examples
1798 --------
1799 >>> import numpy as np
1800
1801 >>> phase = np.linspace(0, np.pi, num=5)
1802 >>> phase[3:] += np.pi
1803 >>> phase
1804 array([ 0. , 0.78539816, 1.57079633, 5.49778714, 6.28318531]) # may vary
1805 >>> np.unwrap(phase)
1806 array([ 0. , 0.78539816, 1.57079633, -0.78539816, 0. ]) # may vary
1807 >>> np.unwrap([0, 1, 2, -1, 0], period=4)
1808 array([0, 1, 2, 3, 4])
1809 >>> np.unwrap([ 1, 2, 3, 4, 5, 6, 1, 2, 3], period=6)

Callers 3

test_simpleMethod · 0.90
test_periodMethod · 0.90
linkcode_resolveFunction · 0.85

Calls 6

sliceFunction · 0.85
cumsumMethod · 0.80
diffFunction · 0.70
asarrayFunction · 0.50
modFunction · 0.50
arrayFunction · 0.50

Tested by 2

test_simpleMethod · 0.72
test_periodMethod · 0.72

Used in the wild real call sites across dependent graphs

searching dependent graphs…