[Numpy-discussion] How to do: y[y<T] = y+T

Anne Archibald aarchiba@physics.mcgill...
Mon Oct 27 08:11:16 CDT 2008

```If what you are trying to do is actually ensure all data is within the
range [a,b], you may be interested to know that python's % operator
works on floating-point numbers:

In [1]: -0.1 % 1
Out[1]: 0.90000000000000002

So if you want all samples in the range (0,1) you can just do y%=1.

Anne

2008/10/27 Nicolas ROUX <nicolas.roux@st.com>:
> Thanks for all of you,
> for this fast and good reply ;-)
>
>
> Nicolas.
>
> -----Original Message-----
> From: numpy-discussion-bounces@scipy.org
> [mailto:numpy-discussion-bounces@scipy.org] On Behalf Of David Douard
> Sent: Monday, October 27, 2008 12:51 PM
> To: numpy-discussion@scipy.org
> Subject: Re: [Numpy-discussion] How to do: y[y<T] = y+T
>
> Le Monday 27 October 2008 12:41:06 Nicolas ROUX, vous avez écrit :
>> Hello,
>>
>> I hope this is not a silly question ;-)
>> I have a Numpy array, and I want to process it with :
>>   "if the value is lower than Threshold, then increase by Threshold"
>>
>>
>> I would like to translate it as:
>>  y[y<Treshold] = y + Treshold
>
> let's see :
>
> y[y<T] += T
>
> Is it what you want ?
>
>>
>> To benefit from the Numpy speed.
>> But this doesn't work, any idea ?
>>
>> Thanks,
>> Cheers,
>> Nicolas.
>>
>> _______________________________________________
>> Numpy-discussion mailing list
>> Numpy-discussion@scipy.org
>> http://projects.scipy.org/mailman/listinfo/numpy-discussion
>
>
>
> --
> David Douard                        LOGILAB, Paris (France), +33 1 45 32 03
> 12
> Formations Python, Zope, Debian :   http://www.logilab.fr/formations
> Développement logiciel sur mesure : http://www.logilab.fr/services
> Informatique scientifique :         http://www.logilab.fr/science
>
> _______________________________________________
> Numpy-discussion mailing list
> Numpy-discussion@scipy.org
> http://projects.scipy.org/mailman/listinfo/numpy-discussion
>
```