aidevelopementtoolkit.data_utils.statistics

get_numerical_statistics(values: np.ndarray) -> Tuple[float, float, float, float]

Compute basic numerical statistics for a 1D array of values.

Parameters:
  • values (ndarray) –

    Array of shape (N,) containing numerical values.

Returns:
  • Tuple[float, float, float, float]
    • min_value: Minimum value in the array.
    • max_value: Maximum value in the array.
    • avg_value: Mean value of the array.
    • std_value: Standard deviation of the array.
Notes

The function ignores NaN values in the input array when computing statistics.

Examples:

>>> import numpy as np
>>> values = np.array([1.0, 2.0, 3.0, np.nan])
>>> get_numerical_statistics(values)
(1.0, 3.0, 2.0, 0.816496580927726)
Source code in aidevelopementtoolkit/data_utils/statistics.py
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
def get_numerical_statistics(values: np.ndarray) -> Tuple[float, float, float, float]:
    """
    Compute basic numerical statistics for a 1D array of values.

    Parameters
    ----------
    values : np.ndarray
        Array of shape `(N,)` containing numerical values.

    Returns
    -------
    Tuple[float, float, float, float]
        - `min_value`: Minimum value in the array.  
        - `max_value`: Maximum value in the array.  
        - `avg_value`: Mean value of the array.  
        - `std_value`: Standard deviation of the array.

    Notes
    -----
    The function ignores NaN values in the input array when computing statistics.

    Examples
    --------
    >>> import numpy as np
    >>> values = np.array([1.0, 2.0, 3.0, np.nan])
    >>> get_numerical_statistics(values)
    (1.0, 3.0, 2.0, 0.816496580927726)
    """

    min_value = np.nanmin(values)
    max_value = np.nanmax(values)
    avg_value = np.nanmean(values)
    std_value = np.nanstd(values)

    return min_value, max_value, avg_value, std_value