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

Vincent Davis vincent at vincentdavis.net
Mon Jul 12 09:36:16 EDT 2010


You might look at this
http://docs.scipy.org/doc/numpy/reference/generated/numpy.extract.html#numpy-extract

Vincent

On Thu, Jun 24, 2010 at 7:08 AM, tashbean <tashbean at googlemail.com> wrote:
> 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
>
> _______________________________________________
> SciPy-User mailing list
> SciPy-User at scipy.org
> http://mail.scipy.org/mailman/listinfo/scipy-user
>



More information about the SciPy-User mailing list