How can I do the following in Python?
- begin with ordered array, x
- randomly sort array elements, according to some probability function
- take first N random elements
- remove chosen elements from original ordered array
- caveat: in the actual problem, I'd like to eliminate the indices corresponding to N elements, not just the values, as
x
may have repeated values. Example: the variablex
from[x,y] = np.meshgrid(xrange,yrange)
may have repeated values, but the indices imply a corresponding y-value, which is important.
My code thusfar:
import numpy as np
N = 5;
x = np.linspace(0,5,11)
pdf = np.exp(-x**2);
pdf = pdf/np.sum(pdf);
x_rand_sorted = np.random.choice(x,N,replace=False,p = pdf)
print 'x:',x
print 'first N random elements:', x_rand_sorted
print 'x without random elements = ??'
Aucun commentaire:
Enregistrer un commentaire