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
00.5641769-0.9968013-1.40034
10.5246001-0.7716667-0.1340367
2-0.70379581.780027-0.2059488
30.58060060.54818351.29076
4-0.94065240.6152958-0.417655


Extract a single component

X1 = X.getMarginal(1)
X1.getSample(5)
X1
00.1660227
10.05610279
2-1.009191
30.006468871
40.3243634


Extract several components

X02 = X.getMarginal([0, 2])
X02.getSample(5)
X0X2
0-0.88005260.4165198
10.4658862-1.333716
2-0.052080850.5812285
3-0.2627790.04679927
4-1.770987-0.156116