Create a random vectorΒΆ

The RandomVector object represents the concept of random variable.

In this example we are going to exhibit some of its main methods.

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

dist3d = ot.Normal(3)
X = ot.RandomVector(dist3d)

Get the dimension

X.getDimension()

Out:

3

Get the mean

X.getMean()

[0,0,0]



Get the covariance

X.getCovariance()

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



Draw a sample

X.getSample(5)
X0X1X2
00.3534472-0.2187709-0.8883468
11.3021081.138971.554364
20.48937730.042574421.501532
3-1.147-0.7282897-1.07746
4-1.269175-0.4687614-0.8110714


Extract a single component

X1 = X.getMarginal(1)
X1.getSample(5)
X1
01.13703
1-0.04030962
21.55857
30.7398424
40.09927194


Extract several components

X02 = X.getMarginal([0, 2])
X02.getSample(5)
X0X2
00.6119656-0.3669958
11.4285-1.908112
22.113194-0.6656038
3-0.11656161.078081
4-0.5657817-0.6800565


Total running time of the script: ( 0 minutes 0.004 seconds)

Gallery generated by Sphinx-Gallery