swectral.moment2d#

swectral.moment2d(data_array_2d, n, standardized=False, reference=None, axis=0, zero_division='add')[source]#

Compute the n-th statistical moment of 2D array-like data along a specified axis.

Parameters:
data_array_2darray_like

2D array-like of int or float. Nan value is omited.

nint

Order of the statistical moment.

standardizedbool, optional

Whether to compute standardized moments.

If True, the moment is scaled by the standard deviation of the data. Default is False.

referencetuple[Union[int,float]], optional

Reference point of the moment.

If not given, the reference point is 0 for first moment and mean for higher-order moments.

axisint, optional

Axis along which the moment is computed.

  • 0 : compute moments column-wise (each column is a variable)

  • 1 : compute moments row-wise (each row is a variable)

The default is 0.

zero_divisionstr

Choose between:

  • "add" : add a small number (1e-30) to denominator to avoid zero.

  • "replace" : replace zero with a small number (1e-30) in the denominator.

  • "nan" : return nan for zero divisions.

  • "numpy" : use default approach of numpy, i.e. return nan for 0 / 0, and +/-inf for non-zero values.

  • "raise" : raise Error for zero divisions.

The default is "add".

Returns:
tuple of float

Target moment.

Return type:

tuple[float, ...]

Examples

Basic usage:

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

>>> moment2d(x, n=1)
>>> moment2d(x, n=2)

Compute along a different axis:

>>> moment2d(x, n=2, axis=1)

Change zero-division handling:

>>> moment2d(x, n=2, zero_division="replace")

Disable standardization:

>>> moment2d(x, n=4, standardized=False)