.. 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-34 .. code-block:: Python generator = numpy.random.Generator(numpy.random.PCG64(0)) values = generator.random((2, 4, 6, 8)) .. GENERATED FROM PYTHON SOURCE LINES 35-36 Create a DescriptiveStatistics object. .. GENERATED FROM PYTHON SOURCE LINES 36-38 .. code-block:: Python ds = pyinterp.DescriptiveStatistics(values) .. GENERATED FROM PYTHON SOURCE LINES 39-53 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 53-55 .. code-block:: Python ds.count() .. rst-class:: sphx-glr-script-out .. code-block:: none array([384], dtype=uint64) .. GENERATED FROM PYTHON SOURCE LINES 56-58 .. code-block:: Python ds.mean() .. rst-class:: sphx-glr-script-out .. code-block:: none array([0.52703051]) .. GENERATED FROM PYTHON SOURCE LINES 59-61 It's possible to get a structured numpy array containing the different statistical variables calculated. .. GENERATED FROM PYTHON SOURCE LINES 61-63 .. code-block:: Python ds.array() .. rst-class:: sphx-glr-script-out .. code-block:: none array([(384, -1.20728744, 0.99720994, 0.52703051, 0.00030069, -0.12457213, 384., 202.37971539, 0.08762152)], dtype=[('count', '` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: ex_descriptive_statistics.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: ex_descriptive_statistics.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_