[SciPy-user] finding values in a list?

josef.pktd at gmail.com josef.pktd at gmail.com
Sat Jul 11 17:25:27 EDT 2009


On Sat, Jul 11, 2009 at 5:22 PM, <josef.pktd at gmail.com> wrote:
> 2009/7/11 Carlos "Guâno" Grohmann <carlos.grohmann at gmail.com>:
>> Sorry if this is too simple or even OT, but say I have a list like
>>
>> [1,2,3,4,5,6,7,8,9]
>>
>> 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
> 7.0
>>>> a[a<0].max() + 6.2
> 6.0

except for the cut and paste error

>>> d = 6.2
>>> a = (np.array([1,7,8,9,2,3,4,5,6]) - d)
>>> a[a>0].min() + d
7.0
>>> a[a<0].max() + d
6.0

>
> Josef
>
>>
>> TIA
>>
>> Carlos
>>
>> --
>> Carlos Henrique Grohmann - Geologist D.Sc.
>> a.k.a. Guano - Linux User #89721
>> ResearcherID: A-9030-2008
>>
>> http://digitalelevation.blogspot.com
>>
>> http://www.igc.usp.br/pessoais/guano
>> _________________
>> Can’t stop the signal.
>> _______________________________________________
>> 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