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()

[0,0,0]



Get the covariance

X.getCovariance()

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



Draw a sample

X.getSample(5)
X0X1X2
02.113194-0.6656038-0.1165616
11.078081-0.5657817-0.6800565
2-0.18357510.768168-2.496996
30.15101350.96697020.4488739
4-0.058308881.596199-0.9100232


Extract a single component

X1 = X.getMarginal(1)
X1.getSample(5)
X1
00.2912405
10.3625414
2-0.7755861
3-0.8029558
4-1.348806


Extract several components

X02 = X.getMarginal([0, 2])
X02.getSample(5)
X0X2
00.01705316-1.728507
1-0.21146910.6865244
20.25683230.5090324
30.4770067-0.1073048
40.9140527-0.1851806


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