def get_stats(list_, axis=None, use_nan=False, use_sum=False, use_median=False,
              size=False):
    """
    Args:
        list_ (listlike): values to get statistics of
        axis (int): if `list_` is ndarray then this specifies the axis

    Returns:
        OrderedDict: stats: dictionary of common numpy statistics
            (min, max, mean, std, nMin, nMax, shape)

    SeeAlso:
        get_stats_str

    CommandLine:
        python -m utool.util_dev --test-get_stats
        python -m utool.util_dev --test-get_stats:1

    Examples0:
        >>> # ENABLE_DOCTEST
        >>> from utool.util_dev import *  # NOQA
        >>> import numpy as np
        >>> import utool
        >>> axis = 0
        >>> np.random.seed(0)
        >>> list_ = np.random.rand(10, 2).astype(np.float32)
        >>> stats = get_stats(list_, axis, use_nan=False)
        >>> result = str(utool.repr4(stats, nl=1, precision=4, with_dtype=True))
        >>> print(result)
        {
            'mean': np.array([0.5206, 0.6425], dtype=np.float32),
            'std': np.array([0.2854, 0.2517], dtype=np.float32),
            'max': np.array([0.9637, 0.9256], dtype=np.float32),
            'min': np.array([0.0202, 0.0871], dtype=np.float32),
            'nMin': np.array([1, 1], dtype=np.int32),
            'nMax': np.array([1, 1], dtype=np.int32),
            'shape': (10, 2),
        }

    Examples1:
        >>> # ENABLE_DOCTEST
        >>> from utool.util_dev import *  # NOQA
        >>> import numpy as np
        >>> import utool
        >>> axis = 0
        >>> rng = np.random.RandomState(0)
        >>> list_ = rng.randint(0, 42, size=100).astype(np.float32)
        >>> list_[4] = np.nan
        >>> stats = get_stats(list_, axis, use_nan=True)
        >>> result = str(utool.repr2(stats, precision=1, strkeys=True))
        >>> print(result)
        {mean: 20.0, std: 13.2, max: 41.0, min: 0.0, nMin: 7, nMax: 3, shape: (100,), num_nan: 1}
    """
    datacast = np.float32
    # Assure input is in numpy format
    if isinstance(list_, np.ndarray):
        nparr = list_
    elif isinstance(list_, list):
        nparr = np.array(list_)
    else:
        nparr = np.array(list(list_))
    # Check to make sure stats are feasible
    if len(nparr) == 0:
        stats = OrderedDict([('empty_list', True)])
        if size:
            stats['size'] = 0
    else:
        if use_nan:
            min_val = np.nanmin(nparr, axis=axis)
            max_val = np.nanmax(nparr, axis=axis)
            mean_ = np.nanmean(nparr, axis=axis)
            std_  = np.nanstd(nparr, axis=axis)
        else:
            min_val = nparr.min(axis=axis)
            max_val = nparr.max(axis=axis)
            mean_ = nparr.mean(axis=axis)
            std_  = nparr.std(axis=axis)
        # number of entries with min/max val
        nMin = np.sum(nparr == min_val, axis=axis)
        nMax = np.sum(nparr == max_val, axis=axis)
        stats = OrderedDict([
            ('mean',  datacast(mean_)),
            ('std',   datacast(std_)),
            ('max',   (max_val)),
            ('min',   (min_val)),
            ('nMin',  np.int32(nMin)),
            ('nMax',  np.int32(nMax)),
        ])
        if size:
            stats['size'] = nparr.size
        else:
            stats['shape'] = nparr.shape
        if use_median:
            stats['med'] = np.nanmedian(nparr)
        if use_nan:
            stats['num_nan'] = np.isnan(nparr).sum()
        if use_sum:
            sumfunc = np.nansum if use_nan else np.sum
            stats['sum'] = sumfunc(nparr, axis=axis)
    return stats
def get_stats ( list_ , axis = None , use_nan = False , use_sum = False , use_median = False , size = False ) : datacast = np . float32 if isinstance ( list_ , np . ndarray ) : nparr = list_ elif isinstance ( list_ , list ) : nparr = np . array ( list_ ) else : nparr = np . array ( list ( list_ ) ) if len ( nparr ) == 0 : stats = OrderedDict ( [ ( 'empty_list' , True ) ] ) if size : stats [ 'size' ] = 0 else : if use_nan : min_val = np . nanmin ( nparr , axis = axis ) max_val = np . nanmax ( nparr , axis = axis ) mean_ = np . nanmean ( nparr , axis = axis ) std_ = np . nanstd ( nparr , axis = axis ) else : min_val = nparr . min ( axis = axis ) max_val = nparr . max ( axis = axis ) mean_ = nparr . mean ( axis = axis ) std_ = nparr . std ( axis = axis ) nMin = np . sum ( nparr == min_val , axis = axis ) nMax = np . sum ( nparr == max_val , axis = axis ) stats = OrderedDict ( [ ( 'mean' , datacast ( mean_ ) ) , ( 'std' , datacast ( std_ ) ) , ( 'max' , ( max_val ) ) , ( 'min' , ( min_val ) ) , ( 'nMin' , np . int32 ( nMin ) ) , ( 'nMax' , np . int32 ( nMax ) ) , ] ) if size : stats [ 'size' ] = nparr . size else : stats [ 'shape' ] = nparr . shape if use_median : stats [ 'med' ] = np . nanmedian ( nparr ) if use_nan : stats [ 'num_nan' ] = np . isnan ( nparr ) . sum ( ) if use_sum : sumfunc = np . nansum if use_nan else np . sum stats [ 'sum' ] = sumfunc ( nparr , axis = axis ) return stats
Args:
        list_ (listlike): values to get statistics of
        axis (int): if `list_` is ndarray then this specifies the axis

    Returns:
        OrderedDict: stats: dictionary of common numpy statistics
            (min, max, mean, std, nMin, nMax, shape)

    SeeAlso:
        get_stats_str

    CommandLine:
        python -m utool.util_dev --test-get_stats
        python -m utool.util_dev --test-get_stats:1

    Examples0:
        >>> # ENABLE_DOCTEST
        >>> from utool.util_dev import *  # NOQA
        >>> import numpy as np
        >>> import utool
        >>> axis = 0
        >>> np.random.seed(0)
        >>> list_ = np.random.rand(10, 2).astype(np.float32)
        >>> stats = get_stats(list_, axis, use_nan=False)
        >>> result = str(utool.repr4(stats, nl=1, precision=4, with_dtype=True))
        >>> print(result)
        {
            'mean': np.array([0.5206, 0.6425], dtype=np.float32),
            'std': np.array([0.2854, 0.2517], dtype=np.float32),
            'max': np.array([0.9637, 0.9256], dtype=np.float32),
            'min': np.array([0.0202, 0.0871], dtype=np.float32),
            'nMin': np.array([1, 1], dtype=np.int32),
            'nMax': np.array([1, 1], dtype=np.int32),
            'shape': (10, 2),
        }

    Examples1:
        >>> # ENABLE_DOCTEST
        >>> from utool.util_dev import *  # NOQA
        >>> import numpy as np
        >>> import utool
        >>> axis = 0
        >>> rng = np.random.RandomState(0)
        >>> list_ = rng.randint(0, 42, size=100).astype(np.float32)
        >>> list_[4] = np.nan
        >>> stats = get_stats(list_, axis, use_nan=True)
        >>> result = str(utool.repr2(stats, precision=1, strkeys=True))
        >>> print(result)
        {mean: 20.0, std: 13.2, max: 41.0, min: 0.0, nMin: 7, nMax: 3, shape: (100,), num_nan: 1}