Random vector manipulationΒΆ

The RandomVector object represents the concept of random variable.

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

[2]:
from __future__ import print_function
import openturns as ot
import math as m
[7]:
# Create a random vector
dist3d = ot.Normal(3)
X = ot.RandomVector(dist3d)
[13]:
# Get the dimension
X.getDimension()
[13]:
3
[8]:
# Get the mean
X.getMean()
[8]:

[0,0,0]

[10]:
# Get the covariance
X.getCovariance()
[10]:

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

[11]:
# Draw a sample
X.getSample(5)
[11]:
X0X1X2
00.3500420865302907-0.35500704918563971.437249310140903
10.81066798246948370.79315601145977-0.4705255986325704
20.26101793529769673-2.2900619818700854-1.2828852904549808
3-1.311781115463341-0.090783826580494890.9957932259165571
4-0.13945281896393122-0.56020560003784750.4454896972990519
[5]:
# Extract a single component
X1 = X.getMarginal(1)
X1.getSample(5)
[5]:
X1
00.6082016512187646
1-1.2661731022166567
2-0.43826561996041397
31.2054782008285756
4-2.1813852346165143
[12]:
# Extract several components
X02 = X.getMarginal([0, 2])
X02.getSample(5)
[12]:
X0X2
00.322925030346612740.44578529818450985
1-1.0380765948630941-0.8567122780208447
20.4736169171884015-0.12549774541256004
30.351417768016114241.7823586399387168
40.070207359297043-0.7813664602347197