Note
Go to the end to download the full example code.
Randomize the lines of a SampleΒΆ
import openturns as ot
In this short example we present a simple way to mix the lines of a sample
thanks to the KPermutationsDistribution
class.
We first define a small sample of size based on a standard unit Gaussian distribution.
distribution = ot.Normal()
N = 5
sample = distribution.getSample(N)
We print the sample :
sample
A new set of randomly mixed indices is a realization of a permutation of elements amongst : This generates a random permutation of the integers .
mixingDistribution = ot.KPermutationsDistribution(N, N)
newIndices = mixingDistribution.getRealization()
The new indices will be these ones :
print("New indices : ", newIndices)
New indices : [2,4,3,0,1]
Eventually the randomized sample is
print(sample[[int(i) for i in newIndices]])
[ X0 ]
0 : [ -0.438266 ]
1 : [ -2.18139 ]
2 : [ 1.20548 ]
3 : [ 0.608202 ]
4 : [ -1.26617 ]