[SciPy-user] finding values in a list?

josef.pktd@gmai... josef.pktd@gmai...
Sat Jul 11 16:25:27 CDT 2009


On Sat, Jul 11, 2009 at 5:22 PM, <josef.pktd@gmail.com> wrote:
> 2009/7/11 Carlos "Guâno" Grohmann <carlos.grohmann@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@scipy.org
>> http://mail.scipy.org/mailman/listinfo/scipy-user
>>
>


More information about the SciPy-user mailing list