Finding NaNs in arrays - Strange outcome [message #92382] |
Sat, 05 December 2015 04:02  |
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   |
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 #92389 is a reply to message #92382] |
Sat, 05 December 2015 13:24   |
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
|
|
|
|