.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_probabilistic_modeling/random_vectors/plot_python_randomvector.py" .. LINE NUMBERS ARE GIVEN BELOW. .. 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_random_vectors_plot_python_randomvector.py: Create a random vector ====================== .. GENERATED FROM PYTHON SOURCE LINES 6-14 In this example we are going to create a distribution or copula. The way to go is inheriting the PythonRandomVector class and overload its methods: - getRealization - getSample - getMean - getCovariance .. GENERATED FROM PYTHON SOURCE LINES 16-23 .. code-block:: default 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) .. GENERATED FROM PYTHON SOURCE LINES 24-25 Inherit PythonRandomVector .. GENERATED FROM PYTHON SOURCE LINES 25-49 .. code-block:: default class RVEC(ot.PythonRandomVector): def __init__(self): super(RVEC, self).__init__(2) self.setDescription(['R', 'S']) def getRealization(self): X = [ot.RandomGenerator.Generate(), 2.0 + ot.RandomGenerator.Generate()] return X def getSample(self, size): X = [] for i in range(size): X.append( [ot.RandomGenerator.Generate(), 2.0 + ot.RandomGenerator.Generate()]) return X def getMean(self): return [0.5, 2.5] def getCovariance(self): return [[1.0, 0.0], [0.0, 1.0]] .. GENERATED FROM PYTHON SOURCE LINES 50-51 Instantiate our distribution .. GENERATED FROM PYTHON SOURCE LINES 51-53 .. code-block:: default randomVector = ot.RandomVector(RVEC()) .. GENERATED FROM PYTHON SOURCE LINES 54-55 Get a sample .. GENERATED FROM PYTHON SOURCE LINES 55-57 .. code-block:: default randomVector.getSample(5) .. raw:: html
v0v1
00.36477832.877147
10.68228822.080219
20.01467382.321082
30.61123682.234876
40.67844992.590527


.. GENERATED FROM PYTHON SOURCE LINES 58-59 Get mean .. GENERATED FROM PYTHON SOURCE LINES 59-61 .. code-block:: default randomVector.getMean() .. raw:: html

[0.5,2.5]



.. GENERATED FROM PYTHON SOURCE LINES 62-63 Compute the probability contained in an interval .. GENERATED FROM PYTHON SOURCE LINES 63-64 .. code-block:: default randomVector.getCovariance() .. raw:: html

[[ 1 0 ]
[ 0 1 ]]



.. rst-class:: sphx-glr-timing **Total running time of the script:** ( 0 minutes 0.002 seconds) .. _sphx_glr_download_auto_probabilistic_modeling_random_vectors_plot_python_randomvector.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_python_randomvector.py ` .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_python_randomvector.ipynb ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_