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

Home » Public Forums » archive » Finding NaNs in arrays - Strange outcome
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
Finding NaNs in arrays - Strange outcome [message #92382] Sat, 05 December 2015 04:02 Go to next message
dmfl0590 is currently offline  dmfl0590
Messages: 17
Registered: December 2015
Junior Member
Hello

I have a 3D array A ( A FLOAT = Array[480, 480, 160]). I wanted to check for NaNs so I had split one 2D array as follows:

A1 = total(A[0:79, 0:79,25])
A2 = total(A[80:159,80:159,25])
A3 = total(A[160:239,160:239,25])
A4 = total(A[240:319,240:319,25])
A5 = total(A[320:399,320:399,25])
A6 = total(A[400:479,400:479,25])

print, 'A1', A1
print, 'A2', A2
print, 'A3', A3
print, 'A4', A4
print, 'A5', A5
print, 'A6', A6

print, 'total',total(A[*,*,25])

PRINT, 'sum',A1+A2+A3+A4+A5+A6

I got the following print results:
A1 682066.
A2 1.51149e+007
A3 9.41048e+006
A4 9.07705e+006
A5 1.18558e+007
A6 62705.1
total NaN
sum 4.62031e+007


Why the total(A[*,*,25]) gave me NaN? Isn't the same thing as the sum?

Can anyone help with this?
Re: Finding NaNs in arrays - Strange outcome [message #92383 is a reply to message #92382] Sat, 05 December 2015 06:38 Go to previous messageGo to next message
David Fanning is currently offline  David Fanning
Messages: 11724
Registered: August 2001
Senior Member
dmfl0590@gmail.com writes:

>
> Hello
>
> I have a 3D array A ( A FLOAT = Array[480, 480, 160]). I wanted to check for NaNs so I had split one 2D array as follows:
>
> A1 = total(A[0:79, 0:79,25])
> A2 = total(A[80:159,80:159,25])
> A3 = total(A[160:239,160:239,25])
> A4 = total(A[240:319,240:319,25])
> A5 = total(A[320:399,320:399,25])
> A6 = total(A[400:479,400:479,25])
>
> print, 'A1', A1
> print, 'A2', A2
> print, 'A3', A3
> print, 'A4', A4
> print, 'A5', A5
> print, 'A6', A6
>
> print, 'total',total(A[*,*,25])
>
> PRINT, 'sum',A1+A2+A3+A4+A5+A6
>
> I got the following print results:
> A1 682066.
> A2 1.51149e+007
> A3 9.41048e+006
> A4 9.07705e+006
> A5 1.18558e+007
> A6 62705.1
> total NaN
> sum 4.62031e+007
>
>
> Why the total(A[*,*,25]) gave me NaN? Isn't the same thing as the sum?
>
> Can anyone help with this?

The way to find NaNs in arrays is to use the Finite function:

http://www.idlcoyote.com/math_tips/nans.html

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: Finding NaNs in arrays - Strange outcome [message #92384 is a reply to message #92383] Sat, 05 December 2015 08:16 Go to previous messageGo to next message
dmfl0590 is currently offline  dmfl0590
Messages: 17
Registered: December 2015
Junior Member
I came across with that page. I wanted to understand though with the print total gives me NaN and the print sum a number.
Re: Finding NaNs in arrays - Strange outcome [message #92385 is a reply to message #92384] Sat, 05 December 2015 08:24 Go to previous messageGo to next message
dmfl0590 is currently offline  dmfl0590
Messages: 17
Registered: December 2015
Junior Member
Also, when I tried the FINITE function:

PRINT, WHERE(FINITE(A[*,*,25], /NAN))

IDL> test
-1

The -1 doesn't make sense...
Re: Finding NaNs in arrays - Strange outcome [message #92386 is a reply to message #92385] Sat, 05 December 2015 08:46 Go to previous messageGo to next message
David Fanning is currently offline  David Fanning
Messages: 11724
Registered: August 2001
Senior Member
dmfl0590@gmail.com writes:

>
> Also, when I tried the FINITE function:
>
> PRINT, WHERE(FINITE(A[*,*,25], /NAN))
>
> IDL> test
> -1
>
> The -1 doesn't make sense...

Try using the COUNT keyword to the WHERE function. It will make more
sense to you. :-)

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: Finding NaNs in arrays - Strange outcome [message #92387 is a reply to message #92386] Sat, 05 December 2015 10:05 Go to previous messageGo to next message
dmfl0590 is currently offline  dmfl0590
Messages: 17
Registered: December 2015
Junior Member
One more question. The 2D array has dimensions [480,480], so 230400 locations.

IDL>
204035 204036 204516 204517

It seems like it gives me the location of values in A that are NaN in 1D. Is that any way to get those locations in 2D or not?
Re: Finding NaNs in arrays - Strange outcome [message #92388 is a reply to message #92387] Sat, 05 December 2015 10:40 Go to previous messageGo to next message
David Fanning is currently offline  David Fanning
Messages: 11724
Registered: August 2001
Senior Member
dmfl0590@gmail.com writes:

>
> One more question. The 2D array has dimensions [480,480], so 230400 locations.
>
> IDL>
> 204035 204036 204516 204517
>
> It seems like it gives me the location of values in A that are NaN in 1D. Is that any way to get those locations in 2D or not?

Yes, Array_Indices:

http://www.idlcoyote.com/tips/where_to_2d.html

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: Finding NaNs in arrays - Strange outcome [message #92389 is a reply to message #92382] Sat, 05 December 2015 13:24 Go to previous messageGo to next message
wlandsman is currently offline  wlandsman
Messages: 743
Registered: June 2000
Senior Member
On Saturday, December 5, 2015 at 7:02:49 AM UTC-5, dmfl...@gmail.com wrote:
> Hello
>
> I have a 3D array A ( A FLOAT = Array[480, 480, 160]). I wanted to check for NaNs so I had split one 2D array as follows:
>
> A1 = total(A[0:79, 0:79,25])
> A2 = total(A[80:159,80:159,25])

You are not "splitting" the array, but selecting disjoint square regions. For example, suppose an NaN value is present in the pixel [75,100,25]. This pixel is not included in either A1 or A2. But it will be included in your total

print, 'total',total(A[*,*,25])

so it is very plausible that total(A[*,*,25]) gives an NaN while A1+A2+A3+A4+A5+A6 does not.

--Wayne
Re: Finding NaNs in arrays - Strange outcome [message #92394 is a reply to message #92389] Mon, 07 December 2015 03:35 Go to previous message
dmfl0590 is currently offline  dmfl0590
Messages: 17
Registered: December 2015
Junior Member
Wayne that was very helpful. I didn't realize that..

Thank you both!
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: ROI of 3D volumes (multiple 2D slices)
Next Topic: Re: IDL_IDLBRIDGE undefined procedure problem

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

Current Time: Wed Oct 08 13:40:25 PDT 2025

Total time taken to generate the page: 0.00554 seconds