NumPy unwrap replaces periodic jumps with a continuous-looking sequence

A sequence of angles can jump numerically when its display returns to the start of a periodic range. NumPy unwrap can replace those large neighbouring jumps by adding or subtracting whole periods. Academia Master Trader presents this English lesson for readers in Chile, using constructed degree values to explain the rule and its limits.

Set the period to match the units

After import numpy as np, define angles = np.array([160.,175.,-170.,-150.]). The call np.unwrap(angles,period=360) returns [160.,175.,190.,210.].

The jump from 175 to minus 170 is minus 345 degrees. Adding one complete period of 360 degrees to the later part turns that change into plus fifteen degrees.

The final value receives the same accumulated adjustment, becoming 210 rather than minus 150. The output therefore keeps the neighbouring progression instead of merely replacing one isolated number.

The default period is two pi, which suits radian input. Degree values need an explicit period of 360; NumPy does not recognise the units from the values alone.

Wrapped degree values and adjusted output

The result uses whole-period corrections

The corrected angles are equivalent modulo 360 to their corresponding inputs. An output of 190 degrees represents the same periodic position as minus 170 degrees.

Unwrap does not force results into a standard interval. Its output can exceed 180 or 360 degrees because retaining a sequence's progression is different from reducing every entry to one cycle.

It also does not sort the input. The original order determines which entries are neighbours and where a correction begins.

Record that order before interpreting an adjusted sequence. Reordering observations changes the neighbouring differences and can change the result.

A discontinuity setting is not a smaller-step command

By default, the relevant threshold is half the period. Setting discont below half the period does not make the function correct every smaller jump.

A larger discont can suppress changes that the default would make. For example, np.unwrap([0.,100.,-160.],period=360,discont=300) leaves those entries unchanged.

The last neighbouring difference is minus 260 degrees. Its magnitude is below the explicit threshold of 300, so that setting leaves the jump in place.

This is a rule for selecting whole-period corrections, not a general instruction to make all adjacent values differ by a chosen small amount.

The selected axis defines neighbouring entries

For multidimensional input, axis identifies the direction along which differences are considered. The default is the last axis, so rows and columns are not interchangeable without checking the arrangement.

Unwrap does not prove that a jump came from periodic wrapping. A real abrupt change can resemble a wrapped jump, and the function applies its numeric rule without knowing the underlying cause.

Continue learning with Academia Master Trader at academiamastertrader.com.br and in Aprenda. State the units, period, ordering and axis before interpreting an unwrapped sequence.