Let's apply the ix_() function to shuffle the Lena photo. The following is the code for this example without comments. The finished code for the recipe can be found in ix.py in this book's code bundle:
This function produces a mesh from multiple sequences. We hand in parameters as one-dimensional sequences and the function gives back a tuple of NumPy arrays, for instance, as follows:
In : ix_([0,1], [2,3])
Out:
(array([[0],[1]]), array([[2, 3]]))
To index the NumPy array with a list of locations, execute the following steps:
Shuffle the array indices.
Make an array with random index numbers with the shuffle() function of the numpy.random subpackage. The function modifies the array in place: