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

Home » Public Forums » archive » Initialize new variable array with nan or -9999 values
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Switch to threaded view of this topic Create a new topic Submit Reply
Initialize new variable array with nan or -9999 values [message #87636] Thu, 20 February 2014 10:31 Go to next message
morganlsilverman is currently offline  morganlsilverman
Messages: 46
Registered: February 2013
Member
Hello,

This seems like it should be so simple but I can't figure out how to do it. I am creating a new array, distance=fltarr(304,336,500) and I want it to be initially filled with either nan or -9999. My results could possibly be 0.0 so I need to know where those are calculated values and not just part of the original array. Thank you.

Sincerely,
Morgan
Re: Initialize new variable array with nan or -9999 values [message #87637 is a reply to message #87636] Thu, 20 February 2014 10:35 Go to previous messageGo to next message
David Fanning is currently offline  David Fanning
Messages: 11724
Registered: August 2001
Senior Member
Morgan Silverman writes:

>
> Hello,
>
> This seems like it should be so simple but I can't figure out how to do it. I am creating a new array, distance=fltarr(304,336,500) and I want it to be initially filled with either nan or -9999. My results could possibly be 0.0 so I need to know where those are calculated values and not just part of the original array. Thank you.

distance=fltarr(304,336,500) + -9999

David
--
David Fanning, Ph.D.
Fanning Software Consulting, Inc.
Coyote's Guide to IDL Programming: http://www.idlcoyote.com/
Sepore ma de ni thue. ("Perhaps thou speakest truth.")
Re: Initialize new variable array with nan or -9999 values [message #87638 is a reply to message #87636] Thu, 20 February 2014 10:36 Go to previous messageGo to next message
John Correira is currently offline  John Correira
Messages: 25
Registered: August 2011
Junior Member
On 02/20/2014 01:31 PM, Morgan Silverman wrote:
> Hello,
>
> This seems like it should be so simple but I can't figure out how to
> do it. I am creating a new array, distance=fltarr(304,336,500) and I
> want it to be initially filled with either nan or -9999. My results
> could possibly be 0.0 so I need to know where those are calculated
> values and not just part of the original array. Thank you.
>
> Sincerely, Morgan
>

Either

distance = fltarr(304,336,500,/NOZERO)
distance[*] = !values.f_nan

or

distance = make_array(304,336,500,/FLOAT,VALUE=!values.f_nan)



John
Re: Initialize new variable array with nan or -9999 values [message #87639 is a reply to message #87637] Thu, 20 February 2014 10:37 Go to previous messageGo to next message
David Fanning is currently offline  David Fanning
Messages: 11724
Registered: August 2001
Senior Member
David Fanning writes:

> distance=fltarr(304,336,500) + -9999

Whoops! Got away from me!

distance=fltarr(304,336,500) - 9999

Or,

distance=fltarr(304,336,500) + !Values.F_NaN

David

--
David Fanning, Ph.D.
Fanning Software Consulting, Inc.
Coyote's Guide to IDL Programming: http://www.idlcoyote.com/
Sepore ma de ni thue. ("Perhaps thou speakest truth.")
Re: Initialize new variable array with nan or -9999 values [message #87643 is a reply to message #87639] Thu, 20 February 2014 13:11 Go to previous messageGo to next message
chris_torrence@NOSPAM is currently offline  chris_torrence@NOSPAM
Messages: 528
Registered: March 2007
Senior Member
On Thursday, February 20, 2014 11:37:22 AM UTC-7, David Fanning wrote:
> David Fanning writes:
>
>
>
>> distance=fltarr(304,336,500) + -9999
>
>
>
> Whoops! Got away from me!
>
>
>
> distance=fltarr(304,336,500) - 9999
>
>
>
> Or,
>
>
>
> distance=fltarr(304,336,500) + !Values.F_NaN
>
>
>
> David
>
>
>
> --
>
> David Fanning, Ph.D.
>
> Fanning Software Consulting, Inc.
>
> Coyote's Guide to IDL Programming: http://www.idlcoyote.com/
>
> Sepore ma de ni thue. ("Perhaps thou speakest truth.")

Also take a look at REPLICATE.
-Chris
Re: Initialize new variable array with nan or -9999 values [message #87644 is a reply to message #87643] Thu, 20 February 2014 13:28 Go to previous messageGo to next message
David Fanning is currently offline  David Fanning
Messages: 11724
Registered: August 2001
Senior Member
Chris Torrence writes:

> Also take a look at REPLICATE.

Since there are about 10 one-line solutions, I suppose the "best" way is
the one containing the fewest keystrokes. ;-)

Cheers,

David
--
David Fanning, Ph.D.
Fanning Software Consulting, Inc.
Coyote's Guide to IDL Programming: http://www.idlcoyote.com/
Sepore ma de ni thue. ("Perhaps thou speakest truth.")
Re: Initialize new variable array with nan or -9999 values [message #87645 is a reply to message #87638] Thu, 20 February 2014 13:33 Go to previous messageGo to next message
Paul Van Delst[1] is currently offline  Paul Van Delst[1]
Messages: 1157
Registered: April 2002
Senior Member
On 02/20/14 13:36, John Correira wrote:
> On 02/20/2014 01:31 PM, Morgan Silverman wrote:
>> Hello,
>>
>> This seems like it should be so simple but I can't figure out how to
>> do it. I am creating a new array, distance=fltarr(304,336,500) and I
>> want it to be initially filled with either nan or -9999. My results
>> could possibly be 0.0 so I need to know where those are calculated
>> values and not just part of the original array. Thank you.
>>
>> Sincerely, Morgan
>>
>
> Either
>
> distance = fltarr(304,336,500,/NOZERO)
> distance[*] = !values.f_nan
>
> or
>
> distance = make_array(304,336,500,/FLOAT,VALUE=!values.f_nan)

+1 on the MAKE_ARRAY for this purpose.

It's more self-documenty (IMO).
Re: Initialize new variable array with nan or -9999 values [message #87646 is a reply to message #87645] Thu, 20 February 2014 13:46 Go to previous messageGo to next message
David Fanning is currently offline  David Fanning
Messages: 11724
Registered: August 2001
Senior Member
Paul van Delst writes:

> +1 on the MAKE_ARRAY for this purpose.
>
> It's more self-documenty (IMO).

What!? Haven't you been watching the Olympics? We want firepower and
quad jumps. I vote for the one that's the most technical and obtuse.

Cheers,

David



--
David Fanning, Ph.D.
Fanning Software Consulting, Inc.
Coyote's Guide to IDL Programming: http://www.idlcoyote.com/
Sepore ma de ni thue. ("Perhaps thou speakest truth.")
Re: Initialize new variable array with nan or -9999 values [message #87647 is a reply to message #87646] Thu, 20 February 2014 14:00 Go to previous messageGo to next message
Paul Van Delst[1] is currently offline  Paul Van Delst[1]
Messages: 1157
Registered: April 2002
Senior Member
On 02/20/14 16:46, David Fanning wrote:
> Paul van Delst writes:
>
>> +1 on the MAKE_ARRAY for this purpose.
>>
>> It's more self-documenty (IMO).
>
> What!? Haven't you been watching the Olympics?

Nope.

> We want firepower and
> quad jumps. I vote for the one that's the most technical and obtuse.

Not for software. Or firepower. In both cases it leads to accidental
(one hopes) foot-shootin'.


cheers,

paulv


p.s. "quad jumps"?
Re: Initialize new variable array with nan or -9999 values [message #87648 is a reply to message #87645] Thu, 20 February 2014 14:14 Go to previous messageGo to next message
wlandsman is currently offline  wlandsman
Messages: 743
Registered: June 2000
Senior Member
On Thursday, February 20, 2014 4:33:01 PM UTC-5, Paul van Delst wrote:
> On 02/20/14 13:36, John Correira wrote:

For large arrays, there is a speed advantage to using REPLICATE or MAKE_ARRAY in which the array is initialized with the correct value, as opposed to

fltarr(304,336,500) - 9999

in which the array is first initialized with zeros, and then 9999 is subtracted from each element. Most computers should be able easily handle a 50 Mb array, so in this case the speed difference would be a fraction of a second. But it is something to keep in mind when arrays are large enough that a factor of two speed improvement matters. --Wayne
Re: Initialize new variable array with nan or -9999 values [message #87653 is a reply to message #87648] Thu, 20 February 2014 17:36 Go to previous messageGo to next message
Heinz Stege is currently offline  Heinz Stege
Messages: 189
Registered: January 2003
Senior Member
On Thu, 20 Feb 2014 14:14:54 -0800 (PST), wlandsman wrote:

> For large arrays, there is a speed advantage to using REPLICATE or MAKE_ARRAY in which the array is initialized with the correct value, as opposed to
>
> fltarr(304,336,500) - 9999
>
> in which the array is first initialized with zeros, and then 9999 is subtracted from each element.

Yes, one should think so. But it is not true. "fltarr()-9999" ist
faster than make_array():

IDL> t0=systime(1) &for i=0,9 do a=fltarr(1000,1000,100)-9999.
&print,systime(1)-t0 &help,a
1.8280001
A FLOAT = Array[1000, 1000, 100]
IDL> t0=systime(1) &for i=0,9 do
a=make_array(1000,1000,100,value=-9999.) &print,systime(1)-t0 &help,a
2.7969999
A FLOAT = Array[1000, 1000, 100]
IDL> print,!version
{ x86 Win32 Windows Microsoft Windows 8.0.1 Oct 5 2010 32
64}

Don't ask me why.

Cheers, Heinz
Re: Initialize new variable array with nan or -9999 values [message #87654 is a reply to message #87653] Thu, 20 February 2014 20:11 Go to previous messageGo to next message
David Fanning is currently offline  David Fanning
Messages: 11724
Registered: August 2001
Senior Member
Heinz Stege writes:

> Yes, one should think so. But it is not true. "fltarr()-9999" ist
> faster than make_array():
>
> IDL> t0=systime(1) &for i=0,9 do a=fltarr(1000,1000,100)-9999.
> &print,systime(1)-t0 &help,a
> 1.8280001
> A FLOAT = Array[1000, 1000, 100]
> IDL> t0=systime(1) &for i=0,9 do
> a=make_array(1000,1000,100,value=-9999.) &print,systime(1)-t0 &help,a
> 2.7969999
> A FLOAT = Array[1000, 1000, 100]
> IDL> print,!version
> { x86 Win32 Windows Microsoft Windows 8.0.1 Oct 5 2010 32 64}

Oh, don't you just hate those guys who use their cell phones to fact
check everything you say! ;-)

Cheers,

David
--
David Fanning, Ph.D.
Fanning Software Consulting, Inc.
Coyote's Guide to IDL Programming: http://www.idlcoyote.com/
Sepore ma de ni thue. ("Perhaps thou speakest truth.")
Re: Initialize new variable array with nan or -9999 values [message #87663 is a reply to message #87653] Fri, 21 February 2014 06:47 Go to previous messageGo to next message
John Correira is currently offline  John Correira
Messages: 25
Registered: August 2011
Junior Member
On 02/20/2014 08:36 PM, Heinz Stege wrote:
> IDL> t0=systime(1) &for i=0,9 do a=fltarr(1000,1000,100)-9999.
> &print,systime(1)-t0 &help,a
> 1.8280001
> A FLOAT = Array[1000, 1000, 100]
> IDL> t0=systime(1) &for i=0,9 do
> a=make_array(1000,1000,100,value=-9999.) &print,systime(1)-t0 &help,a
> 2.7969999
> A FLOAT = Array[1000, 1000, 100]
> IDL> print,!version
> { x86 Win32 Windows Microsoft Windows 8.0.1 Oct 5 2010 32
> 64}


MAKE_ARRAY is faster on my machine:

IDL> tic
IDL> for i=0,9 do a=fltarr(1000,1000,100)-9999.
IDL> toc
IDL> help, a

Elapsed time is 3.018326s
A FLOAT = Array[1000, 1000, 100]

IDL> tic
IDL> for i=0,9 do a=make_array(1000,1000,100,value=-9999.)
IDL> toc
IDL> help, a

Elapsed time is 2.075103s
A FLOAT = Array[1000, 1000, 100]

IDL> print,!version
{ x86_64 linux unix linux 8.2 Apr 10 2012 64
64}
Re: Initialize new variable array with nan or -9999 values [message #87664 is a reply to message #87663] Fri, 21 February 2014 06:58 Go to previous message
David Fanning is currently offline  David Fanning
Messages: 11724
Registered: August 2001
Senior Member
John Correira writes:

> MAKE_ARRAY is faster on my machine:
>
> IDL> tic
> IDL> for i=0,9 do a=fltarr(1000,1000,100)-9999.
> IDL> toc
> IDL> help, a
>
> Elapsed time is 3.018326s
> A FLOAT = Array[1000, 1000, 100]
>
> IDL> tic
> IDL> for i=0,9 do a=make_array(1000,1000,100,value=-9999.)
> IDL> toc
> IDL> help, a
>
> Elapsed time is 2.075103s
> A FLOAT = Array[1000, 1000, 100]
>
> IDL> print,!version
> { x86_64 linux unix linux 8.2 Apr 10 2012 64
> 64}

I think you have to be a little careful how you do this experiment. But,
starting IDL from scratch each time (.reset) and then running the
Make_Array method or the Add-To method, I get these results on my
Windows 64-bit machine with IDL 8.2.3:

Make_Array Method: 1.572
Add-To Method: 1.811

Maybe 15% faster. I don't think I would be losing sleep over it. :-)

Cheers,

David

--
David Fanning, Ph.D.
Fanning Software Consulting, Inc.
Coyote's Guide to IDL Programming: http://www.idlcoyote.com/
Sepore ma de ni thue. ("Perhaps thou speakest truth.")
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: Problem with cgcmdwindow__define
Next Topic: Position, normal coordinates, and multiple images

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

Current Time: Wed Oct 08 15:39:42 PDT 2025

Total time taken to generate the page: 0.00648 seconds