FINITE function [message #90049] |
Wed, 21 January 2015 04:00  |
g.nacarts
Messages: 148 Registered: November 2013
|
Senior Member |
|
|
Hi I used the FINITE() function as suggested to find out whether there are nans or infinity numbers in my array. The problem is that I cannot understand the output of that function. I set the keyword SIGN = 1 but I got -1 inthe outcome.
Below is a part of the code:
DataArray ; contains the 3D data
for i = 0, 199 do begin
for j = 0, 199 do begin
Barray = DataArray[*,i,j] - Array[i,j]
print, where(finite(Barray), /INFINITY, SIGN=1))
endfor
endfor
I got the -1 value thousands of times maybe and I am not even able to figure out in which place of that array there are infinity or nans (if there are any)
Can anyone help with this?
|
|
|
Re: FINITE function [message #90050 is a reply to message #90049] |
Wed, 21 January 2015 04:14   |
andeh
Messages: 23 Registered: April 2011
|
Junior Member |
|
|
On Wednesday, 21 January 2015 12:00:29 UTC, g.na...@gmail.com wrote:
> Hi I used the FINITE() function as suggested to find out whether there are nans or infinity numbers in my array. The problem is that I cannot understand the output of that function. I set the keyword SIGN = 1 but I got -1 inthe outcome.
>
> Below is a part of the code:
>
> DataArray ; contains the 3D data
>
> for i = 0, 199 do begin
> for j = 0, 199 do begin
> Barray = DataArray[*,i,j] - Array[i,j]
> print, where(finite(Barray), /INFINITY, SIGN=1))
> endfor
> endfor
>
> I got the -1 value thousands of times maybe and I am not even able to figure out in which place of that array there are infinity or nans (if there are any)
>
> Can anyone help with this?
Your test is only looking for positive infinity so all finite numbers, negative infinities, and NaNs will not be flagged. e.g.
IDL> PRINT, FINITE( 1.0, /INFINITY, SIGN=1), WHERE(FINITE( 1.0, /INFINITY, SIGN=1))
IDL> PRINT, FINITE( !VALUES.F_NAN , /INFINITY, SIGN=1), WHERE(FINITE( !VALUES.F_NAN , /INFINITY, SIGN=1))
0 -1
IDL> PRINT, FINITE( -!VALUES.F_NAN , /INFINITY, SIGN=1), WHERE(FINITE( -!VALUES.F_NAN , /INFINITY, SIGN=1))
0 -1
IDL> PRINT, FINITE( 1.0 / 0.0 , /INFINITY, SIGN=1), WHERE(FINITE( 1.0 / 0.0, /INFINITY, SIGN=1))
1 0
IDL> PRINT, FINITE( -1.0 / 0.0 , /INFINITY, SIGN=1), WHERE(FINITE( -1.0 / 0.0, /INFINITY, SIGN=1))
0 -1
You are getting -1 values from WHERE(). This means that there are no matching elements in FINITE(Barray).
To search for all non-finite numbers, make your search
WHERE( ~FINITE(Barray) )
|
|
|
Re: FINITE function [message #90051 is a reply to message #90050] |
Wed, 21 January 2015 04:20   |
andeh
Messages: 23 Registered: April 2011
|
Junior Member |
|
|
On Wednesday, 21 January 2015 12:14:55 UTC, AJAS wrote:
> On Wednesday, 21 January 2015 12:00:29 UTC, g.na...@gmail.com wrote:
>> Hi I used the FINITE() function as suggested to find out whether there are nans or infinity numbers in my array. The problem is that I cannot understand the output of that function. I set the keyword SIGN = 1 but I got -1 inthe outcome.
>>
>> Below is a part of the code:
>>
>> DataArray ; contains the 3D data
>>
>> for i = 0, 199 do begin
>> for j = 0, 199 do begin
>> Barray = DataArray[*,i,j] - Array[i,j]
>> print, where(finite(Barray), /INFINITY, SIGN=1))
>> endfor
>> endfor
>>
>> I got the -1 value thousands of times maybe and I am not even able to figure out in which place of that array there are infinity or nans (if there are any)
>>
>> Can anyone help with this?
Ah. Just saw your previous posts.
You are looking for positive infinities?
You have not put the brackets in the correct place around your FINITE function and you could test to see if there are any valid elements using the COUNT keyword to WHERE.
How about:
for i = 0, 199 do begin
for j = 0, 199 do begin
Barray = DataArray[*,i,j] - Array[i,j]
w = where(finite(Barray, /INFINITY, SIGN=1), COUNT=count)
IF count GT 0 THEN PRINT, w
endfor
endfor
|
|
|
|
|
Re: FINITE function [message #90055 is a reply to message #90054] |
Wed, 21 January 2015 05:52   |
andeh
Messages: 23 Registered: April 2011
|
Junior Member |
|
|
On Wednesday, 21 January 2015 13:49:52 UTC, AJAS wrote:
> On Wednesday, 21 January 2015 13:35:13 UTC, g.na...@gmail.com wrote:
>> I've got a quite old version of IDL 6.4. And I got the error that Keyword COUNT not allowed in call to: WHERE
>
> Ok.
>
> Then just test that the first element of the returned array w is not -1.
>
> w = WHERE( FINITE(Barray,/INFINITY,SIGN=1) )
> IF w[0] NE -1 THEN PRINT, w
Oh, my bad. I misremembered the WHERE command. COUNT is a parameter, not a keyword.
Does,
w = WHERE( FINITE(Barray,/INFINITY, SIGN=1, count )
work?
|
|
|
Re: FINITE function [message #90056 is a reply to message #90054] |
Wed, 21 January 2015 05:53   |
andeh
Messages: 23 Registered: April 2011
|
Junior Member |
|
|
On Wednesday, 21 January 2015 13:49:52 UTC, AJAS wrote:
> On Wednesday, 21 January 2015 13:35:13 UTC, g.na...@gmail.com wrote:
>> I've got a quite old version of IDL 6.4. And I got the error that Keyword COUNT not allowed in call to: WHERE
>
> Ok.
>
> Then just test that the first element of the returned array w is not -1.
>
> w = WHERE( FINITE(Barray,/INFINITY,SIGN=1) )
> IF w[0] NE -1 THEN PRINT, w
Oh, my bad. I misremembered the WHERE command. COUNT is a parameter, not a keyword.
Does,
w = WHERE( FINITE(Barray,/INFINITY, SIGN=1), count )
work?
|
|
|
|