how to get the index of numpy.random.choice? - python
Question: Is it possible to modify the numpy.random.choice function in order to make it
return the index of the chosen element? Basically, I want to create a list and
select elements randomly without replacement

    
    
    import numpy as np
    >>> a = [1,4,1,3,3,2,1,4]
    >>> np.random.choice(a)
    >>> 4
    >>> a
    >>> [1,4,1,3,3,2,1,4]
    

`a.remove(np.random.choice(a))` will remove the first element of the list with
that value it encounters (`a[1]` in the example above), which may not be the
chosen element (eg, `a[7]`).


Answer: 
    numpy.random.choice(a, size=however_many, replace=False)
    

If you want a sample without replacement, just ask numpy to make you one.
Don't loop and draw items repeatedly. That'll produce bloated code and
horrible performance.

Example:

    
    
    >>> a = numpy.arange(10)
    >>> a
    array([0, 1, 2, 3, 4, 5, 6, 7, 8, 9])
    >>> numpy.random.choice(a, size=5, replace=False)
    array([7, 5, 8, 6, 2])
    

