fast_array_utils.stats
¶
Statistics utilities for 2D arrays.
All of these allow you to specify an axis
,
which allows you to choose whether to compute the statistic across rows, columns, or all elements.
- fast_array_utils.stats.is_constant(x: NDArray[Any] | types.CSBase | types.CupyArray, /, *, axis: None = None) bool ¶
- fast_array_utils.stats.is_constant(x: NDArray[Any] | types.CSBase, /, *, axis: Literal[0, 1]) NDArray[np.bool]
- fast_array_utils.stats.is_constant(x: types.CupyArray, /, *, axis: Literal[0, 1]) types.CupyArray
- fast_array_utils.stats.is_constant(x: types.DaskArray, /, *, axis: Literal[0, 1, None] = None) types.DaskArray
Check whether values in array are constant.
- Parameters:
x – Array to check.
axis – Axis to reduce over.
- Returns:
If
axis
isNone
, return if all values were constant. Else returns a boolean array withTrue
representing constant columns/rows.
Example
>>> import numpy as np >>> x = np.array([ ... [0, 1, 2], ... [0, 0, 0], ... ]) >>> is_constant(x) False >>> is_constant(x, axis=0) array([ True, False, False]) >>> is_constant(x, axis=1) array([False, True])
- fast_array_utils.stats.mean(x: ndarray[tuple[int, ...], dtype[Any]] | csc_matrix | csr_matrix | csc_array | csr_array | ndarray | csr_matrix | csc_matrix | Dataset | Array, /, *, axis: Literal[None] = None, dtype: DTypeLike | None = None) np.number[Any] ¶
- fast_array_utils.stats.mean(x: ndarray[tuple[int, ...], dtype[Any]] | csc_matrix | csr_matrix | csc_array | csr_array | Dataset | Array, /, *, axis: Literal[0, 1], dtype: DTypeLike | None = None) NDArray[np.number[Any]]
- fast_array_utils.stats.mean(x: ndarray | csr_matrix | csc_matrix, /, *, axis: Literal[0, 1], dtype: DTypeLike | None = None) types.CupyArray
- fast_array_utils.stats.mean(x: types.DaskArray, /, *, axis: Literal[0, 1], dtype: ToDType[Any] | None = None) types.DaskArray
Mean over both or one axis.
- Parameters:
x – Array to calculate mean(s) for.
axis – Axis to reduce over.
- Returns:
If
axis
isNone
, then the sum over all elements is returned as a scalar. Otherwise, the sum over the given axis is returned as a 1D array.
Example
>>> import numpy as np >>> x = np.array([ ... [0, 1, 2], ... [0, 0, 0], ... ]) >>> mean(x) np.float64(0.5) >>> mean(x, axis=0) array([0. , 0.5, 1. ]) >>> mean(x, axis=1) array([1., 0.])
See also
- fast_array_utils.stats.mean_var(x: ndarray[tuple[int, ...], dtype[Any]] | csc_matrix | csr_matrix | csc_array | csr_array | ndarray | csr_matrix | csc_matrix, /, *, axis: Literal[None] = None, correction: int = 0) tuple[np.float64, np.float64] ¶
- fast_array_utils.stats.mean_var(x: ndarray[tuple[int, ...], dtype[Any]] | csc_matrix | csr_matrix | csc_array | csr_array, /, *, axis: Literal[0, 1], correction: int = 0) tuple[NDArray[np.float64], NDArray[np.float64]]
- fast_array_utils.stats.mean_var(x: ndarray | csr_matrix | csc_matrix, /, *, axis: Literal[0, 1], correction: int = 0) tuple[types.CupyArray, types.CupyArray]
- fast_array_utils.stats.mean_var(x: types.DaskArray, /, *, axis: Literal[0, 1, None] = None, correction: int = 0) tuple[types.DaskArray, types.DaskArray]
Mean and variance over both or one axis.
- Parameters:
x – Array to compute mean and variance for.
axis – Axis to reduce over.
correction – Degrees of freedom correction.
- Returns:
- mean
See below:
- var
If
axis
isNone
, the mean and variance over all elements are returned as scalars. Otherwise, the means and variances over the given axis are returned as 1D arrays.
Example
>>> import numpy as np >>> x = np.array([ ... [0, 1, 2], ... [0, 0, 0], ... ]) >>> mean_var(x) (np.float64(0.5), np.float64(0.5833333333333334)) >>> mean_var(x, axis=0) (array([0. , 0.5, 1. ]), array([0. , 0.25, 1. ])) >>> mean_var(x, axis=1) (array([1., 0.]), array([0.66666667, 0. ]))
See also
- fast_array_utils.stats.sum(x: ndarray[tuple[int, ...], dtype[Any]] | csc_matrix | csr_matrix | csc_array | csr_array | ndarray | csr_matrix | csc_matrix | Dataset | Array, /, *, axis: None = None, dtype: DTypeLike | None = None) np.number[Any] ¶
- fast_array_utils.stats.sum(x: ndarray[tuple[int, ...], dtype[Any]] | csc_matrix | csr_matrix | csc_array | csr_array | Dataset | Array, /, *, axis: Literal[0, 1], dtype: DTypeLike | None = None) NDArray[Any]
- fast_array_utils.stats.sum(x: ndarray | csr_matrix | csc_matrix, /, *, axis: Literal[0, 1], dtype: DTypeLike | None = None) types.CupyArray
- fast_array_utils.stats.sum(x: types.DaskArray, /, *, axis: Literal[0, 1, None] = None, dtype: DTypeLike | None = None) types.DaskArray
Sum over both or one axis.
- Parameters:
x – Array to sum up.
axis – Axis to reduce over.
- Returns:
If
axis
isNone
, then the sum over all elements is returned as a scalar. Otherwise, the sum over the given axis is returned as a 1D array.
Example
>>> import numpy as np >>> x = np.array([ ... [0, 1, 2], ... [0, 0, 0], ... ]) >>> sum(x) np.int64(3) >>> sum(x, axis=0) array([0, 1, 2]) >>> sum(x, axis=1) array([3, 0])
See also