swectral.nderiv#

swectral.nderiv(data_array_2d, n, axis=1, padding='nan')[source]#

Compute the n-th numerical derivative of 1D data series contained in a 2D array-like object.

Each row or column is treated as an independent 1D series, depending on the selected axis.

Parameters:
data_array_2darray_like of real numbers

Two-dimensional array-like input data.

The input must be convertible to a 2D array and support numeric operations. Each 1D slice along the computation axis is treated as an independent variable.

nint

Order of the derivative. Must be a positive integer.

axisint, optional

Axis along which to compute the derivative.

  • 0 : compute derivatives row-wise (each row is a variable, columns are samples)

  • 1 : compute derivatives column-wise (each column is a variable, rows are samples)

Default is 1.

paddingint or float or str or None, optional

Boundary padding strategy applied to derivative arrays. Choose between:

  • "nan" : pad with NaN values

  • "edge" : pad using edge values

  • int or float : pad with the specified numeric value

  • None : no padding

If None is specified, the output size along the computation axis is reduced by 2 * n. Default is "nan".

Returns:
array_like

The n-th derivative of the input data along the specified axis.

If padding is applied, the output has the same shape as the input. Otherwise, the output size is reduced along the computation axis.

Return type:

Any

Examples

Basic usage:

>>> x = [[1, 2, 3, 4],
...      [5, 6, 7, 8],
...      [9, 10, 11, 12],
...      [13, 14, 15, 16]]

>>> nderiv(x, 1)
>>> nderiv(x, 2)

Compute along a different axis:

>>> nderiv(x, 2, axis=0)

Use different padding strategies:

>>> nderiv(x, 2, padding="nan")
>>> nderiv(x, 2, padding="edge")

Pad with a custom numeric value:

>>> nderiv(x, 2, padding=0)

Disable padding:

>>> nderiv(x, 2, padding=None)