.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_examples/ex_descriptive_statistics.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. note:: :class: sphx-glr-download-link-note :ref:`Go to the end ` to download the full example code or to run this example in your browser via Binder .. rst-class:: sphx-glr-example-title .. _sphx_glr_auto_examples_ex_descriptive_statistics.py: ********************** Descriptive Statistics ********************** Numpy offers many statistical functions, but if you want to obtain several statistical variables from the same array, it's necessary to process the data several times to calculate the various parameters. This example shows how to use the DescriptiveStatistics class to obtain several statistical variables with a single calculation. Also, the calculation algorithm is incremental and is more numerically stable. .. note:: Pébay, P., Terriberry, T.B., Kolla, H. et al. Numerically stable, scalable formulas for parallel and online computation of higher-order multivariate central moments with arbitrary weights. Comput Stat 31, 1305–1325, 2016, https://doi.org/10.1007/s00180-015-0637-z .. GENERATED FROM PYTHON SOURCE LINES 24-29 .. code-block:: Python import dask.array import numpy import pyinterp .. GENERATED FROM PYTHON SOURCE LINES 30-31 Create a random array .. GENERATED FROM PYTHON SOURCE LINES 31-33 .. code-block:: Python values = numpy.random.random_sample((2, 4, 6, 8)) .. GENERATED FROM PYTHON SOURCE LINES 34-35 Create a DescriptiveStatistics object. .. GENERATED FROM PYTHON SOURCE LINES 35-37 .. code-block:: Python ds = pyinterp.DescriptiveStatistics(values) .. GENERATED FROM PYTHON SOURCE LINES 38-52 The constructor will calculate the statistical variables on the provided data. The calculated variables are stored in the instance and can be accessed using different methods: * mean * var * std * skewness * kurtosis * min * max * sum * sum_of_weights * count .. GENERATED FROM PYTHON SOURCE LINES 52-54 .. code-block:: Python ds.count() .. rst-class:: sphx-glr-script-out .. code-block:: none array([384], dtype=uint64) .. GENERATED FROM PYTHON SOURCE LINES 55-57 .. code-block:: Python ds.mean() .. rst-class:: sphx-glr-script-out .. code-block:: none array([0.50151422]) .. GENERATED FROM PYTHON SOURCE LINES 58-60 It's possible to get a structured numpy array containing the different statistical variables calculated. .. GENERATED FROM PYTHON SOURCE LINES 60-62 .. code-block:: Python ds.array() .. rst-class:: sphx-glr-script-out .. code-block:: none array([(384, -1.17292331, 0.99964469, 0.50151422, 0.00674238, 0.00654089, 384., 192.58146049, 0.07907892)], dtype=[('count', '` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: ex_descriptive_statistics.py ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_