numpy.random.choice is a handy tool for sampling random elements from a 1D array:
In [94]: numpy.random.choice(numpy.arange(5), 10)
Out[94]: array([3, 1, 4, 3, 4, 3, 2, 4, 1, 1])
But the docs specify that a param must be one dimensional. But if I want to get a random selection of rows from a 2D array (for example, random samples for a one hot encoder), then numpy.random.choice cannot be used anymore.
So if my input is:
array([[ 1., 0., 0.],
[ 0., 1., 0.],
[ 0., 0., 1.]])
How can I get n rows in random fashion from this array, like this? (n = 10)
array([[ 0., 0., 1.],
[ 1., 0., 0.],
[ 0., 0., 1.],
[ 0., 0., 1.],
[ 1., 0., 0.],
[ 0., 1., 0.],
[ 1., 0., 0.],
[ 0., 0., 1.],
[ 1., 0., 0.],
[ 1., 0., 0.]])