Statistics - Maple Programming Help

Home : Support : Online Help : Statistics and Data Analysis : Statistics Package : Data Manipulation : Statistics/Shuffle

Statistics

 Shuffle
 apply random permutation to a data sample

 Calling Sequence Shuffle(X, options)

Parameters

 X - options - (optional) equation of the form inplace = truefalse; indicates whether to change the argument

Description

 • The Shuffle command applies a random permutation to X.
 • The first parameter X is a data sample - given as e.g. a Vector.
 • An option inplace = true or inplace = false can be specified as a second argument. With inplace = true, Shuffle will change X in place if it is an Array or a Vector; with inplace = false, Shuffle will return a new (shuffled) copy of X. If X is a list, then Shuffle returns a new copy either way. The default is inplace = false.
 The option inplace = true can be abbreviated to inplace.

Notes

 • The Shuffle command accepts non-numeric data.

Examples

 > $\mathrm{with}\left(\mathrm{Statistics}\right):$
 > $A≔\mathrm{Array}\left(\left[a,b,c,d,e,f,g,h,i,j\right]\right)$
 ${A}{≔}\left[\begin{array}{cccccccccc}{a}& {b}& {c}& {d}& {e}& {f}& {g}& {h}& {i}& {j}\end{array}\right]$ (1)
 > $\mathrm{A1}≔\mathrm{Shuffle}\left(A\right)$
 ${\mathrm{A1}}{≔}\left[\begin{array}{cccccccccc}{g}& {d}& {e}& {a}& {i}& {f}& {b}& {h}& {j}& {c}\end{array}\right]$ (2)
 > $\mathrm{A2}≔\mathrm{Shuffle}\left(A\right)$
 ${\mathrm{A2}}{≔}\left[\begin{array}{cccccccccc}{c}& {e}& {j}& {g}& {a}& {f}& {b}& {h}& {i}& {d}\end{array}\right]$ (3)
 > $\mathrm{A3}≔\mathrm{Shuffle}\left(A\right)$
 ${\mathrm{A3}}{≔}\left[\begin{array}{cccccccccc}{c}& {d}& {i}& {b}& {h}& {e}& {f}& {j}& {g}& {a}\end{array}\right]$ (4)
 > $\mathrm{sort}\left(\mathrm{A1}\right)$
 $\left[\begin{array}{cccccccccc}{a}& {b}& {c}& {d}& {e}& {f}& {g}& {h}& {i}& {j}\end{array}\right]$ (5)
 > $B≔\mathrm{Array}\left(\left[\mathrm{seq}\left(i,i=1..10\right)\right]\right)$
 ${B}{≔}\left[\begin{array}{cccccccccc}{1}& {2}& {3}& {4}& {5}& {6}& {7}& {8}& {9}& {10}\end{array}\right]$ (6)
 > $C≔\mathrm{Shuffle}\left(B\right)$
 ${C}{≔}\left[\begin{array}{cccccccccc}{10}& {3}& {5}& {1}& {2}& {6}& {9}& {4}& {8}& {7}\end{array}\right]$ (7)
 > $\mathrm{OrderByRank}\left(A,C\right)$
 $\left[\begin{array}{cccccccccc}{d}& {e}& {b}& {h}& {c}& {f}& {j}& {i}& {g}& {a}\end{array}\right]$ (8)

So far, $A$ itself has not changed. The inplace option changes this.

 > $A$
 $\left[\begin{array}{cccccccccc}{a}& {b}& {c}& {d}& {e}& {f}& {g}& {h}& {i}& {j}\end{array}\right]$ (9)
 > $\mathrm{Shuffle}\left(A,\mathrm{inplace}\right):$$A$
 $\left[\begin{array}{cccccccccc}{e}& {d}& {h}& {i}& {b}& {j}& {g}& {c}& {f}& {a}\end{array}\right]$ (10)

Note that the output of Maple's random number generator is reproducible after a restart. If this is undesirable, one can use the randomize command.

 > $\mathrm{restart}$
 > $\mathrm{with}\left(\mathrm{Statistics}\right):$
 > $A≔\mathrm{Array}\left(\left[a,b,c,d,e,f,g,h,i,j\right]\right)$
 ${A}{≔}\left[\begin{array}{cccccccccc}{a}& {b}& {c}& {d}& {e}& {f}& {g}& {h}& {i}& {j}\end{array}\right]$ (11)
 > $\mathrm{A1}≔\mathrm{Shuffle}\left(A\right)$
 ${\mathrm{A1}}{≔}\left[\begin{array}{cccccccccc}{g}& {d}& {e}& {a}& {i}& {f}& {b}& {h}& {j}& {c}\end{array}\right]$ (12)
 > $\mathrm{restart}$
 > $\mathrm{with}\left(\mathrm{Statistics}\right):$
 > $A≔\mathrm{Array}\left(\left[a,b,c,d,e,f,g,h,i,j\right]\right)$
 ${A}{≔}\left[\begin{array}{cccccccccc}{a}& {b}& {c}& {d}& {e}& {f}& {g}& {h}& {i}& {j}\end{array}\right]$ (13)
 > $\mathrm{randomize}\left(\right)$
 ${9540227395}$ (14)
 > $\mathrm{A1}≔\mathrm{Shuffle}\left(A\right)$
 ${\mathrm{A1}}{≔}\left[\begin{array}{cccccccccc}{i}& {b}& {d}& {j}& {a}& {f}& {g}& {e}& {h}& {c}\end{array}\right]$ (15)