comp.lang.idl-pvwave archive
Messages from Usenet group comp.lang.idl-pvwave, compiled by Paulo Penteado

Home » Public Forums » archive » make all array values equal to zero
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Return to the default flat view Create a new topic Submit Reply
Re: make all array values equal to zero [message #89863 is a reply to message #89862] Thu, 11 December 2014 09:52 Go to previous messageGo to previous message
Michael Galloy is currently offline  Michael Galloy
Messages: 1114
Registered: April 2006
Senior Member
On 12/11/14, 9:59 AM, alx wrote:
> IDL> A=randomn(rien,10000000)
> IDL> tic & A *= (A gt 1) & toc
> % Time elapsed: 0.078000069 seconds.
> IDL> tic & A[where(A gt 1,/NULL)]=0 & toc
> % Time elapsed: 0.047000170 seconds.
>
> The "where" solution appears to be somewhat faster.

Your solution should scale with the number of elements which match the
condition.

So for 50% of the elements matching:

IDL> n = 10000000L
IDL> a = 2.0 * randomu(seed, n)
IDL> tic & a *= (A gt 1) & toc
Elapsed Time: 0.024550
IDL> a = 2.0 * randomu(seed, n)
IDL> tic & A[where(A gt 1,/NULL)]=0 & toc
Elapsed Time: 0.023005

For about 15% of the elements matching:

IDL> a = randomn(seed, n)
IDL> tic & A[where(A gt 1,/NULL)]=0 & toc
Elapsed Time: 0.014616

For all of the elements matching:

IDL> a = randomu(seed, n) + 1.0
IDL> tic & A[where(A gt 1,/NULL)]=0 & toc
Elapsed Time: 0.024564

But, in any case, the WHERE solution seems equal or faster in all cases.

Mike
--
Michael Galloy
www.michaelgalloy.com
Modern IDL: A Guide to IDL Programming (http://modernidl.idldev.com)
Research Mathematician
Tech-X Corporation
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: plot positional degrees
Next Topic: Rendering method software vs hardware

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ] [ PDF ]

Current Time: Wed Oct 08 18:56:08 PDT 2025

Total time taken to generate the page: 0.00419 seconds