# 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]:

 X0 X1 X2 0 0.3500420865302907 -0.3550070491856397 1.437249310140903 1 0.8106679824694837 0.79315601145977 -0.4705255986325704 2 0.26101793529769673 -2.2900619818700854 -1.2828852904549808 3 -1.311781115463341 -0.09078382658049489 0.9957932259165571 4 -0.13945281896393122 -0.5602056000378475 0.4454896972990519
[5]:

# Extract a single component
X1 = X.getMarginal(1)
X1.getSample(5)

[5]:

 X1 0 0.6082016512187646 1 -1.2661731022166567 2 -0.43826561996041397 3 1.2054782008285756 4 -2.1813852346165143
[12]:

# Extract several components
X02 = X.getMarginal([0, 2])
X02.getSample(5)

[12]:

 X0 X2 0 0.32292503034661274 0.44578529818450985 1 -1.0380765948630941 -0.8567122780208447 2 0.4736169171884015 -0.12549774541256004 3 0.35141776801611424 1.7823586399387168 4 0.070207359297043 -0.7813664602347197