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.

import openturns as ot

ot.Log.Show(ot.Log.NONE)

Create a random vector

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

Get the dimension

X.getDimension()
3

Get the mean

X.getMean()
class=Point name=Unnamed dimension=3 values=[0,0,0]


Get the covariance

X.getCovariance()

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



Draw a sample

X.getSample(5)
X0X1X2
0-0.36699581.4285-1.908112
12.113194-0.6656038-0.1165616
21.078081-0.5657817-0.6800565
3-0.18357510.768168-2.496996
40.15101350.96697020.4488739


Extract a single component

X1 = X.getMarginal(1)
X1.getSample(5)
X1
0-0.05830888
11.596199
2-0.9100232
30.2912405
40.3625414


Extract several components

X02 = X.getMarginal([0, 2])
X02.getSample(5)
X0X2
0-0.7755861-0.8029558
1-1.3488060.01705316
2-1.728507-0.2114691
30.68652440.2568323
40.50903240.4770067