.. only:: html .. note:: :class: sphx-glr-download-link-note Click :ref:`here ` to download the full example code .. rst-class:: sphx-glr-example-title .. _sphx_glr_auto_probabilistic_modeling_distributions_plot_random_vector_manipulation.py: Random vector manipulation ========================== The RandomVector object represents the concept of random variable. In this example we are going to exhibit some of its main methods. .. code-block:: default from __future__ import print_function import openturns as ot import openturns.viewer as viewer from matplotlib import pylab as plt import math as m ot.Log.Show(ot.Log.NONE) Create a random vector .. code-block:: default dist3d = ot.Normal(3) X = ot.RandomVector(dist3d) Get the dimension .. code-block:: default X.getDimension() .. rst-class:: sphx-glr-script-out Out: .. code-block:: none 3 Get the mean .. code-block:: default X.getMean() .. raw:: html

[0,0,0]



Get the covariance .. code-block:: default X.getCovariance() .. raw:: html

[[ 1 0 0 ]
[ 0 1 0 ]
[ 0 0 1 ]]



Draw a sample .. code-block:: default X.getSample(5) .. raw:: html
X0X1X2
00.23949031.008846-0.3819995
10.1030435-0.4948338-1.717802
20.1429553-0.6950194-0.1156185
3-1.687796-0.114902-1.712393
4-1.07275-0.47458191.040955


Extract a single component .. code-block:: default X1 = X.getMarginal(1) X1.getSample(5) .. raw:: html
X1
00.672975
11.292529
21.163747
30.2549519
4-1.431553


Extract several components .. code-block:: default X02 = X.getMarginal([0, 2]) X02.getSample(5) .. raw:: html
X0X2
00.19961580.07590005
11.021166-1.149774
20.60659790.4826356
3-0.6285791-0.05952591
41.304801-0.8920438


.. rst-class:: sphx-glr-timing **Total running time of the script:** ( 0 minutes 0.002 seconds) .. _sphx_glr_download_auto_probabilistic_modeling_distributions_plot_random_vector_manipulation.py: .. only :: html .. container:: sphx-glr-footer :class: sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_random_vector_manipulation.py ` .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_random_vector_manipulation.ipynb ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_