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

Home » Public Forums » archive » Re: operation with array of NaNs
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
Re: operation with array of NaNs [message #52426] Thu, 01 February 2007 06:43
inardello is currently offline  inardello
Messages: 2
Registered: February 2007
Junior Member
Thank you all.
: )

I know what to do, now.

I->
Re: operation with array of NaNs [message #52431 is a reply to message #52426] Wed, 31 January 2007 17:07 Go to previous message
jschwab@gmail.com is currently offline  jschwab@gmail.com
Messages: 30
Registered: December 2006
Member
Ignore that bit of extraneous text at the end. A cut/paste gone bad.

Josiah
Re: operation with array of NaNs [message #52432 is a reply to message #52431] Wed, 31 January 2007 17:06 Go to previous message
jschwab@gmail.com is currently offline  jschwab@gmail.com
Messages: 30
Registered: December 2006
Member
Just to summarize what has already been said.

WHERE returns a list of indicies. So if you do,

IDL> print, where( [2, 3, 5, 7] eq 5)

2

If you do,

IDL> print, where( [2, 3, 5, 7] gt 4)

2 3

But if you do,

IDL> print, where( [2, 3, 5, 7] lt 0)

-1

In the case that the condition inside the WHERE is never satisfied,
IDL returns -1
And when you call, n_elements on the returned value of -1, you
rightfully get 1.

As others have said, IDL will store the number of times the condition
was satisfied in the variable name that you put after the condition in
the WHERE.

So you do,

IDL> void = where( [2, 3, 5, 7] lt 0, count)
IDL> print, count

0

And there is the anticipated value of 0.

Using a count variable is a good practice when subscripting with the
result of WHERE.

Instead of

my_new_array= my_old_array[ where( my_old_array gt foo) ]

Do

new_indicies = where( my_old_array gt foo, count)
if count gt 0 then my_new_array = my_old_array[new_indicies]

I guarantee you that will save you a headache at somepoint.

Josiah

When you use the where statement and the condition is NEVER met, IDL
returns -1.
This is one
On Jan 31, 6:01 pm, inarde...@odu.edu wrote:
> Hello there,
>
> I am quite new to IDL and found an interesting problem.
>
> I have an array of elements (5x5).
> All the elements in the array are NaN(s).
>
> When I ask what is the number of locations (n_elements) where the
> elements of this array are e.g.: "finite", the answer is "1".
>
> If the array contains 1 finite elements (and the rest is Nan(s)), the
> answer to the same question is still "1".
> If the array contains 2 finite elements, the answer to the same
> question is (finally..) "2".
>
>> From there we progress normally.
>
> So why can't I have an answer "0" when the array is only filled with
> NaNs?
>
> The same problem appears with other forms of analysis of the same
> array. For example, "what is the number of elements greater than 10?"
> The answer is still "1"
>
> Thank you for your comments.
>
> I->
Re: operation with array of NaNs [message #52436 is a reply to message #52432] Wed, 31 January 2007 15:10 Go to previous message
Jean H. is currently offline  Jean H.
Messages: 472
Registered: July 2006
Senior Member
don't use n_elements on the result of where, but the counter IN where...

a= [1,2,3]
b = where(a eq 10, counter)

print, b ==> -1
print, n_elements(b) ==> 1
print, counter ==> 0

Jean

inardello@odu.edu wrote:
> Hello there,
>
> I am quite new to IDL and found an interesting problem.
>
> I have an array of elements (5x5).
> All the elements in the array are NaN(s).
>
> When I ask what is the number of locations (n_elements) where the
> elements of this array are e.g.: "finite", the answer is "1".
>
> If the array contains 1 finite elements (and the rest is Nan(s)), the
> answer to the same question is still "1".
> If the array contains 2 finite elements, the answer to the same
> question is (finally..) "2".
>> From there we progress normally.
>
> So why can't I have an answer "0" when the array is only filled with
> NaNs?
>
> The same problem appears with other forms of analysis of the same
> array. For example, "what is the number of elements greater than 10?"
> The answer is still "1"
>
> Thank you for your comments.
>
> I->
>
Re: operation with array of NaNs [message #52437 is a reply to message #52436] Wed, 31 January 2007 15:17 Go to previous message
news.qwest.net is currently offline  news.qwest.net
Messages: 137
Registered: September 2005
Senior Member
<inardello@odu.edu> wrote in message
news:1170284491.683686.134280@a34g2000cwb.googlegroups.com.. .
> Hello there,
>
> I am quite new to IDL and found an interesting problem.
>
> I have an array of elements (5x5).
> All the elements in the array are NaN(s).
>
> When I ask what is the number of locations (n_elements) where the
> elements of this array are e.g.: "finite", the answer is "1".


I think you want total(), instead of N_elements().

IDL> print,total(finite([!values.f_nan,!values.f_nan]))

0.000000





Cheers,

bob
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: Re: Cutting/Exclude ROI's based on overlapping
Next Topic: netCDF/CF conventions

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

Current Time: Wed Oct 08 18:39:21 PDT 2025

Total time taken to generate the page: 0.00664 seconds