.. 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_python_randomvector.py: Creation of a custom random vector ================================== 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 .. 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) Inherit PythonRandomVector .. 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]] Instanciate our distribution .. code-block:: default randomVector = ot.RandomVector(RVEC()) Get a sample .. code-block:: default randomVector.getSample(5) .. raw:: html
v0v1
00.20015772.751968
10.3748572.529779
20.71198892.497759
30.92117652.555468
40.37537692.568851


Get mean .. code-block:: default randomVector.getMean() .. raw:: html

[0.5,2.5]



Compute the probability contained in an interval .. 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_distributions_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 `_