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.

from __future__ import print_function
import openturns as ot
import openturns.viewer as viewer
from matplotlib import pylab as plt
import math as m
ot.Log.Show(ot.Log.NONE)

Create a random vector

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

Get the dimension

X.getDimension()

Out:

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
00.23949031.008846-0.3819995
10.1030435-0.4948338-1.717802
20.1429553-0.6950194-0.1156185
3-1.687796-0.114902-1.712393
4-1.07275-0.47458191.040955


Extract a single component

X1 = X.getMarginal(1)
X1.getSample(5)
X1
00.672975
11.292529
21.163747
30.2549519
4-1.431553


Extract several components

X02 = X.getMarginal([0, 2])
X02.getSample(5)
X0X2
00.19961580.07590005
11.021166-1.149774
20.60659790.4826356
3-0.6285791-0.05952591
41.304801-0.8920438


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

Gallery generated by Sphinx-Gallery