[SciPy-User] more efficient way of dealing with numpy arrays?

tashbean tashbean@googlemail....
Thu Jun 24 08:08:49 CDT 2010


Hi,

I would like to pick certain rows of an array based on matching the
first column with options contained in another array e.g. I have this
array:

parameter_list =
array([['Q10', 'scipy.stats.uniform(2,10-2)'],
       ['mpe', 'scipy.stats.uniform(0.,1.)'],
       ['rdr_a', 'scipy.stats.uniform(5e-5,1.24-5e-5)'],
       ['rdr_b', 'scipy.stats.uniform(-60.18,-3.41--60.18)']],
      dtype='|S40')

I have an array which contains the strings of the first column which I
would like to pick out e.g.

param_options = ['Q10' , 'mpe']

My solution of how to do this is as follows:

new_params = numpy.array([])

for i in xrange(len(param_options)):
     new_params = numpy.append(new_params,
parameter_list[parameter_list[:,0]==param_options[i]])

Is there a more efficient way of doing this?

Thank you for your help!
Tash



More information about the SciPy-User mailing list