# Sample manipulationΒΆ

This example will describe the main statistical functionalities on data through the Sample object.

In [1]:

from __future__ import print_function
import openturns as ot

In [2]:

# Generate a sample of dimension 3
sample = ot.Normal(3).getSample(500)
sample[:5]

Out[2]:

X0 X1 X2 0.6082016512187646 -1.2661731022166567 -0.43826561996041397 1.2054782008285756 -2.1813852346165143 0.3500420865302907 -0.3550070491856397 1.437249310140903 0.8106679824694837 0.79315601145977 -0.4705255986325704 0.26101793529769673 -2.2900619818700854 -1.2828852904549808 -1.311781115463341
In [26]:

# Get min and max per component
sample.getMin(), sample.getMax()

Out[26]:

(class=Point name=Unnamed dimension=3 values=[-2.4067,-3.24637,-3.09834],
class=Point name=Unnamed dimension=3 values=[3.15958,3.01263,2.63821])

In [4]:

# Get the range per component (xmax-xmin)
sample.computeRange()

Out[4]:


[5.56628,6.25899,5.73655]

In [5]:

# Get the mean per component
sample.computeMean()

Out[5]:


[-0.0421682,-0.0168704,0.0580127]

In [6]:

# Get the standard deviation per component
sample.computeStandardDeviationPerComponent()

Out[6]:


[0.96048,1.01449,0.995846]

In [7]:

# Get the Variance per component
sample.computeVariance()

Out[7]:


[0.922521,1.02919,0.991709]

In [8]:

# Get the Skewness per component
sample.computeSkewness()

Out[8]:


[0.200045,-0.0429991,-0.0712751]

In [9]:

# Get the Kurtosis per component
sample.computeKurtosis()

Out[9]:


[3.15748,3.03583,3.02072]

In [10]:

# Get the median per component
sample.computeMedian()

Out[10]:


[-0.0497493,-0.0559353,0.0312677]

In [11]:

# Get the empirical 0.95 quantile per component
sample.computeQuantilePerComponent(0.95)

Out[11]:


[1.54329,1.64875,1.69843]

In [12]:

# Get the sample covariance
sample.computeCovariance()

Out[12]:


[[ 0.922521 0.0383477 0.051918 ]
[ 0.0383477 1.02919 0.0143437 ]
[ 0.051918 0.0143437 0.991709 ]]

In [13]:

# Get the sample standard deviation
sample.computeStandardDeviation()

Out[13]:


[[ 0.96048 0 0 ]
[ 0.0399256 1.01371 0 ]
[ 0.0540543 0.0120208 0.994305 ]]

In [14]:

# Get the sample Pearson correlation matrix
sample.computePearsonCorrelation()

Out[14]:


[[ 1 0.0393553 0.0542798 ]
[ 0.0393553 1 0.0141978 ]
[ 0.0542798 0.0141978 1 ]]

In [15]:

# Get  the sample Kendall correlation matrix
sample.computeKendallTau()

Out[15]:


[[ 1 0.0367936 0.0292906 ]
[ 0.0367936 1 0.0209539 ]
[ 0.0292906 0.0209539 1 ]]

In [16]:

# Get  the sample Spearman  correlation matrix
sample.computeSpearmanCorrelation()

Out[16]:


[[ 1 0.0544864 0.0444143 ]
[ 0.0544864 1 0.0313186 ]
[ 0.0444143 0.0313186 1 ]]

In [17]:

# Get the value of the empirical CDF at a point
point = [1.1, 2.2, 3.3]
sample.computeEmpiricalCDF(point)

Out[17]:

0.862