[Numpy-discussion] inplace unary operations?

Pierre Barbier de Reuille pierre at barbierdereuille.net
Sun Aug 31 11:04:25 EDT 2014


Just to point out another solution to change the sign:

>>> arr *= -1

Both solutions take the same time on my computer. However, the boolean
equivalent:

>>> arr ^= True

is a lot slower than using negative.

My two cents ...



-- 
Dr. Barbier de Reuille, Pierre
Institute of Plant Sciences
Altenbergrain 21, CH-3013 Bern, Switzerland
http://www.botany.unibe.ch/associated/systemsx/index.php


On 31 August 2014 15:31, <josef.pktd at gmail.com> wrote:

>
>
>
> On Sat, Aug 30, 2014 at 1:45 PM, Nathaniel Smith <njs at pobox.com> wrote:
>
>> On Sat, Aug 30, 2014 at 6:43 PM,  <josef.pktd at gmail.com> wrote:
>> > Is there a way to negate a boolean, or to change the sign of a float
>> inplace
>> > ?
>>
>> np.logical_not(arr, out=arr)
>> np.negative(arr, out=arr)
>>
>
> Thanks Nathaniel.
>
> np.negative might save a bit of memory and time when we have to negate the
> loglikelihood all the time.
>
> Josef
>
>
>
>>
>> -n
>>
>> --
>> Nathaniel J. Smith
>> Postdoctoral researcher - Informatics - University of Edinburgh
>> http://vorpus.org
>> _______________________________________________
>> NumPy-Discussion mailing list
>> NumPy-Discussion at scipy.org
>> http://mail.scipy.org/mailman/listinfo/numpy-discussion
>>
>
>
> _______________________________________________
> NumPy-Discussion mailing list
> NumPy-Discussion at scipy.org
> http://mail.scipy.org/mailman/listinfo/numpy-discussion
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/numpy-discussion/attachments/20140831/171230b4/attachment.html>


More information about the NumPy-Discussion mailing list