.. 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 6-8 .. code-block:: Python import openturns as ot .. GENERATED FROM PYTHON SOURCE LINES 9-11 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 13-14 We first define a small sample of size :math:`N` based on a standard unit gaussian distribution. .. GENERATED FROM PYTHON SOURCE LINES 14-18 .. code-block:: Python distribution = ot.Normal() N = 5 sample = distribution.getSample(N) .. GENERATED FROM PYTHON SOURCE LINES 19-20 We print the sample : .. GENERATED FROM PYTHON SOURCE LINES 20-22 .. code-block:: Python print(sample) .. rst-class:: sphx-glr-script-out .. code-block:: none [ X0 ] 0 : [ -0.721533 ] 1 : [ -0.241223 ] 2 : [ -1.78796 ] 3 : [ 0.40136 ] 4 : [ 1.36783 ] .. GENERATED FROM PYTHON SOURCE LINES 23-25 A new set of randomly mixed indices is a realization of a permutation of N elements amongst N : .. GENERATED FROM PYTHON SOURCE LINES 25-28 .. code-block:: Python mixingDistribution = ot.KPermutationsDistribution(N, N) newIndices = mixingDistribution.getSample(1)[0, :] .. GENERATED FROM PYTHON SOURCE LINES 29-30 The new indices will be these ones : .. GENERATED FROM PYTHON SOURCE LINES 30-32 .. code-block:: Python print("New indices : ", newIndices) .. rst-class:: sphx-glr-script-out .. code-block:: none New indices : [2,3,1,4,0] .. GENERATED FROM PYTHON SOURCE LINES 33-34 Eventually the randomized sample is .. GENERATED FROM PYTHON SOURCE LINES 34-35 .. code-block:: Python print(sample[[int(i) for i in newIndices]]) .. rst-class:: sphx-glr-script-out .. code-block:: none [ X0 ] 0 : [ -1.78796 ] 1 : [ 0.40136 ] 2 : [ -0.241223 ] 3 : [ 1.36783 ] 4 : [ -0.721533 ] .. _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 `