.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_examples/numpy/digitize.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. note:: :class: sphx-glr-download-link-note Click :ref:`here ` 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_numpy_digitize.py: ========================= 4.3 quantile and digitize ========================= This file describes the concept of quantile and how to cclculate it in numpy and various functions around it. .. GENERATED FROM PYTHON SOURCE LINES 10-15 .. code-block:: default import numpy as np print(np.__version__) .. rst-class:: sphx-glr-script-out .. code-block:: none 1.26.4 .. GENERATED FROM PYTHON SOURCE LINES 16-21 .. code-block:: default x = np.array([1,2,3,4,5]) np.quantile(x, 0.5) .. rst-class:: sphx-glr-script-out .. code-block:: none 3.0 .. GENERATED FROM PYTHON SOURCE LINES 22-27 .. code-block:: default x = np.array([1,2,2,3,3,4,5]) np.quantile(x, 0.5) .. rst-class:: sphx-glr-script-out .. code-block:: none 3.0 .. GENERATED FROM PYTHON SOURCE LINES 28-31 so quantile actually means that what will be that value that if we distribute the values of the array 50% on one side and 50% on other side. 50% because we have used 0.5 .. GENERATED FROM PYTHON SOURCE LINES 31-36 .. code-block:: default x = np.array([0, 1, 2, 3, 4, 5, 6, 7, 8, 9]) print(np.quantile(x, 0.5)) .. rst-class:: sphx-glr-script-out .. code-block:: none 4.5 .. GENERATED FROM PYTHON SOURCE LINES 37-40 .. code-block:: default print(np.quantile(x, 0.2)) .. rst-class:: sphx-glr-script-out .. code-block:: none 1.8 .. GENERATED FROM PYTHON SOURCE LINES 41-44 .. code-block:: default print(np.quantile(x, [0.2, 0.5])) .. rst-class:: sphx-glr-script-out .. code-block:: none [1.8 4.5] .. GENERATED FROM PYTHON SOURCE LINES 45-48 .. code-block:: default print(np.quantile(np.arange(10, 20), [0.2, 0.5])) .. rst-class:: sphx-glr-script-out .. code-block:: none [11.8 14.5] .. GENERATED FROM PYTHON SOURCE LINES 49-50 what if the array is 2D .. GENERATED FROM PYTHON SOURCE LINES 52-54 .. code-block:: default print(np.quantile(np.arange(20).reshape(-1, 10), [0.2, 0.5])) .. rst-class:: sphx-glr-script-out .. code-block:: none [3.8 9.5] .. GENERATED FROM PYTHON SOURCE LINES 55-61 .. code-block:: python np.quantile([1.8, 11.8], 0.2) # 3.8 np.quantile([4.5, 14.5], 0.5) # 9.5 .. rst-class:: sphx-glr-timing **Total running time of the script:** ( 0 minutes 0.005 seconds) .. _sphx_glr_download_auto_examples_numpy_digitize.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: binder-badge .. image:: images/binder_badge_logo.svg :target: https://mybinder.org/v2/gh/AtrCheema/python-seekho/master?urlpath=lab/tree/notebooks/auto_examples/numpy/digitize.ipynb :alt: Launch binder :width: 150 px .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: digitize.py ` .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: digitize.ipynb ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_