Source From Here
Question
I'm writing some modelling routines in NumPy that need to select cells randomly from a NumPy array and do some processing on them. All cells must be selected without replacement (as in, once a cell has been selected it can't be selected again, but all cells must be selected by the end).
How-To
How about using numpy.random.shuffle or numpy.random.permutation if you still need the original array? If you need to change the array in-place than you can create an index array like this:
Question
I'm writing some modelling routines in NumPy that need to select cells randomly from a NumPy array and do some processing on them. All cells must be selected without replacement (as in, once a cell has been selected it can't be selected again, but all cells must be selected by the end).
How-To
How about using numpy.random.shuffle or numpy.random.permutation if you still need the original array? If you need to change the array in-place than you can create an index array like this:
沒有留言:
張貼留言