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 N elements amongst N :
mixingDistribution = ot.KPermutationsDistribution(N, N)
newIndices = mixingDistribution.getSample(1)[0, :]
The new indices will be these ones :
print("New indices : ", newIndices)
New indices : [2,3,1,4,0]
Eventually the randomized sample is
print(sample[[int(i) for i in newIndices]])
[ X0 ]
0 : [ -1.78796 ]
1 : [ 0.40136 ]
2 : [ -0.241223 ]
3 : [ 1.36783 ]
4 : [ -0.721533 ]