[SciPy-user] finding values in a list?
Sat Jul 11 16:29:29 CDT 2009
On Sat, Jul 11, 2009 at 5:22 PM, <firstname.lastname@example.org> wrote:
> 2009/7/11 Carlos "Guâno" Grohmann <email@example.com>:
>> Sorry if this is too simple or even OT, but say I have a list like
>> and I want to get the values just below and above a given value.
>> So, if I enter 6.2, I get 6 and 7.
>> but how?
> maybe like this
>>>> a = (np.array([1,2,3,4,5,6,7,8,9])-6.1)
>>>> a[a>0].min() + 6.2
>>>> a[a<0].max() + 6.2
Yet another solution (though I too don't know if it's optimal). This
will work if you know that your values are always going to be within 1
as in your example.
>>> import numpy as np
>>> L = [1,2,3,4,5,6,7,8]
>>> A = np.array(L)
>>> index = np.where(np.abs((A-6.2))<1)
More information about the SciPy-user