.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_data_analysis/manage_data_and_samples/plot_randomize_sample_lines.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. .. rst-class:: sphx-glr-example-title .. _sphx_glr_auto_data_analysis_manage_data_and_samples_plot_randomize_sample_lines.py: Randomize the lines of a Sample =============================== .. GENERATED FROM PYTHON SOURCE LINES 7-9 .. code-block:: Python import openturns as ot .. GENERATED FROM PYTHON SOURCE LINES 10-12 In this short example we present a simple way to mix the lines of a sample thanks to the :class:`~openturns.KPermutationsDistribution` class. .. GENERATED FROM PYTHON SOURCE LINES 14-15 We first define a small sample of size :math:`\sampleSize` based on a standard unit Gaussian distribution. .. GENERATED FROM PYTHON SOURCE LINES 15-19 .. code-block:: Python distribution = ot.Normal() N = 5 sample = distribution.getSample(N) .. GENERATED FROM PYTHON SOURCE LINES 20-21 We print the sample : .. GENERATED FROM PYTHON SOURCE LINES 21-23 .. code-block:: Python sample .. raw:: html
X0
00.6082017
1-1.266173
2-0.4382656
31.205478
4-2.181385


.. GENERATED FROM PYTHON SOURCE LINES 24-27 A new set of randomly mixed indices is a realization of a permutation of :math:`\sampleSize` elements amongst :math:`\sampleSize`: This generates a random permutation of the integers :math:`\{0, ..., \sampleSize - 1\}`. .. GENERATED FROM PYTHON SOURCE LINES 27-30 .. code-block:: Python mixingDistribution = ot.KPermutationsDistribution(N, N) newIndices = mixingDistribution.getRealization() .. GENERATED FROM PYTHON SOURCE LINES 31-32 The new indices will be these ones : .. GENERATED FROM PYTHON SOURCE LINES 32-34 .. code-block:: Python print("New indices : ", newIndices) .. rst-class:: sphx-glr-script-out .. code-block:: none New indices : [2,4,3,0,1] .. GENERATED FROM PYTHON SOURCE LINES 35-36 Eventually the randomized sample is .. GENERATED FROM PYTHON SOURCE LINES 36-37 .. code-block:: Python print(sample[[int(i) for i in newIndices]]) .. rst-class:: sphx-glr-script-out .. code-block:: none [ X0 ] 0 : [ -0.438266 ] 1 : [ -2.18139 ] 2 : [ 1.20548 ] 3 : [ 0.608202 ] 4 : [ -1.26617 ] .. _sphx_glr_download_auto_data_analysis_manage_data_and_samples_plot_randomize_sample_lines.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_randomize_sample_lines.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_randomize_sample_lines.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: plot_randomize_sample_lines.zip `