bundles / scipy 1.17.1 / scipy / stats / _stats_py / gstd
function
scipy.stats._stats_py:gstd
source: /scipy/stats/_stats_py.py :2939
Signature
def gstd ( a , axis = 0 , ddof = 1 , * , keepdims = False , nan_policy = propagate ) Summary
Calculate the geometric standard deviation of an array.
Extended Summary
The geometric standard deviation describes the spread of a set of numbers where the geometric mean is preferred. It is a multiplicative factor, and so a dimensionless quantity.
It is defined as the exponential of the standard deviation of the natural logarithms of the observations.
Parameters
a: array_likeAn array containing finite, strictly positive, real numbers.
axis: int, tuple or None, optionalAxis along which to operate. Default is 0. If None, compute over the whole array
a.ddof: int, optionalDegree of freedom correction in the calculation of the geometric standard deviation. Default is 1.
keepdims: boolean, optionalIf this is set to
True, the axes which are reduced are left in the result as dimensions with length one. With this option, the result will broadcast correctly against the input array.nan_policy: {'propagate', 'omit', 'raise'}, default: 'propagate'Defines how to handle input NaNs.
propagate: if a NaN is present in the axis slice (e.g. row) along which the statistic is computed, the corresponding entry of the output will be NaN.omit: NaNs will be omitted when performing the calculation. If insufficient data remains in the axis slice along which the statistic is computed, the corresponding entry of the output will be NaN.raise: if a NaN is present, aValueErrorwill be raised.
Returns
gstd: ndarray or floatAn array of the geometric standard deviation. If
axisis None orais a 1d array a float is returned.
Notes
Mathematically, the sample geometric standard deviation can be defined in terms of the natural logarithms of the observations :
where is the number of observations, is the adjustment ddof to the degrees of freedom, and denotes the mean of the natural logarithms of the observations. Note that the default ddof=1 is different from the default value used by similar functions, such as numpy.std and numpy.var.
When an observation is infinite, the geometric standard deviation is NaN (undefined). Non-positive observations will also produce NaNs in the output because the natural logarithm (as opposed to the complex logarithm) is defined and finite only for positive reals. The geometric standard deviation is sometimes confused with the exponential of the standard deviation, exp(std(a)). Instead, the geometric standard deviation is exp(std(log(a))).
Array API Standard Support
gstd has experimental support for Python Array API Standard compatible backends in addition to NumPy. Please consider testing these features by setting an environment variable SCIPY_ARRAY_API=1 and providing CuPy, PyTorch, JAX, or Dask arrays as array arguments. The following combinations of backend and device (or other capability) are supported.
==================== ==================== ==================== Library CPU GPU ==================== ==================== ==================== NumPy ✅ n/a CuPy n/a ✅ PyTorch ✅ ✅ JAX ✅ ✅ Dask ✅ n/a ==================== ==================== ====================
See
dev-arrayapifor more information.
Examples
Find the geometric standard deviation of a log-normally distributed sample. Note that the standard deviation of the distribution is one; on a log scale this evaluates to approximately ``exp(1)``.import numpy as np from scipy.stats import gstd rng = np.random.default_rng() sample = rng.lognormal(mean=0, sigma=1, size=1000)✓
gstd(sample)
✗a = np.arange(1, 25).reshape(2, 3, 4)
✓gstd(a, axis=None) gstd(a, axis=2) gstd(a, axis=(1,2))✗
See also
Aliases
-
scipy.stats.gstd