Note
Click here to download the full example code
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)
X0 | X1 | X2 | |
---|---|---|---|
0 | 0.2394903 | 1.008846 | -0.3819995 |
1 | 0.1030435 | -0.4948338 | -1.717802 |
2 | 0.1429553 | -0.6950194 | -0.1156185 |
3 | -1.687796 | -0.114902 | -1.712393 |
4 | -1.07275 | -0.4745819 | 1.040955 |
Extract a single component
X1 = X.getMarginal(1)
X1.getSample(5)
X1 | |
---|---|
0 | 0.672975 |
1 | 1.292529 |
2 | 1.163747 |
3 | 0.2549519 |
4 | -1.431553 |
Extract several components
X02 = X.getMarginal([0, 2])
X02.getSample(5)
X0 | X2 | |
---|---|---|
0 | 0.1996158 | 0.07590005 |
1 | 1.021166 | -1.149774 |
2 | 0.6065979 | 0.4826356 |
3 | -0.6285791 | -0.05952591 |
4 | 1.304801 | -0.8920438 |
Total running time of the script: ( 0 minutes 0.002 seconds)