# 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.2394903 1.008846 -0.3819995 0.1030435 -0.4948338 -1.717802 0.1429553 -0.6950194 -0.1156185 -1.687796 -0.114902 -1.712393 -1.07275 -0.4745819 1.040955

Extract a single component

```X1 = X.getMarginal(1)
X1.getSample(5)
```
X1 0.672975 1.292529 1.163747 0.2549519 -1.431553

Extract several components

```X02 = X.getMarginal([0, 2])
X02.getSample(5)
```
X0 X2 0.1996158 0.07590005 1.021166 -1.149774 0.6065979 0.4826356 -0.6285791 -0.05952591 1.304801 -0.8920438

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

Gallery generated by Sphinx-Gallery