[Numpy-discussion] extracting a random subset of a vector

Curzio Basso curzio.basso at unibas.ch
Tue Aug 31 06:04:00 EDT 2004

Hi all, I have an optimization problem.

I currently use the following code to select a random subset of a rank-1 


import numarray as NA
import numarray.random_array as RA

N = 1000
M = 100
full = NA.arange(N)
subset = full[RA.permutation(N)][:M]


However, it's quite slow (at least with N~40k), and from the hotshot 
output is looks like it's the indexing, not the permutation, which takes 
Does anyone have a suggestion on a faster pure-python implementation?


More information about the NumPy-Discussion mailing list