[SciPy-User] Limit array to range

Kevin Gullikson kevin.gullikson.signup@gmail....
Mon Apr 1 11:35:25 CDT 2013


You could use numpy.where and numpy.logical_and perhaps. I'm not sure it
looks any prettier though...

indices = numpy.where( numpy.logical_and(data1[:,0] >= xrange[0],
data1[:,0] <= xrange[1]) )
data1 = data1[indices]


On Mon, Apr 1, 2013 at 11:30 AM, Florian Lindner <mailinglists@xgm.de>wrote:

> Hello,
>
> I have two arrays from which I want to discard all rows where the first
> column
> is not within xrange:
>
> This does perfectly what i want:
>
> xrange = [-2, 3]
> data1 = data1[ data1[:,0] >= xrange[0] ]
> data1 = data1[ data1[:,0] <= xrange[1] ]
> data2 = data2[ data2[:,0] >= xrange[0] ]
> data2 = data2[ data2[:,0] <= xrange[1] ]
>
> But I can hardly believe that this is the most elegant way. How would do
> such
> an easy task with numpy/scipy?
>
>
> Regards,
> Florian
> _______________________________________________
> SciPy-User mailing list
> SciPy-User@scipy.org
> http://mail.scipy.org/mailman/listinfo/scipy-user
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.scipy.org/pipermail/scipy-user/attachments/20130401/4847a55e/attachment.html 


More information about the SciPy-User mailing list