array handling [message #52128] |
Sat, 06 January 2007 02:59  |
jochem.verelst@gmail.
Messages: 19 Registered: January 2007
|
Junior Member |
|
|
Hi all,
I am a newbie in IDL. Although I cannot handle the following problem, I
am sure for the 'Masters' this is peanuts.
The problem:
I wish to filter an array of redundant data in one line. This is a part
of the line to be filtered:
-Inf -NaN -Inf 0.542373 2.39394 2.28125
0.000000 0.000000 0.000000
3.21053 1.21839 0.000000 -NaN 0.967213
2.03448 0.724138 0.000000 0.000000 0.000000
-NaN
With WHERE I can get rid of the zeros, but I dont know how to exclude
the '-NaN' and '-Inf'.
Any help would be most welcome,
greetz, Jochem
|
|
|
|
Re: array handling [message #74187 is a reply to message #52128] |
Mon, 03 January 2011 11:10   |
Paul Van Delst[1]
Messages: 1157 Registered: April 2002
|
Senior Member |
|
|
David Fanning wrote:
> bing999 writes:
>
>> Thanks for answering. But what I want is to divide the number of
>> elements of my array by 2 by keeping only elements with odd index for
>> instance. Is there an IDL routine which does it?
>
> IDL> array = indgen(10)
> IDL> print, array
> 0 1 2 3 4 5 6 7 8 9
> IDL> print, rebin(array, 5)
> 0 2 4 6 8
Or for the IDL 8-ers out there:
IDL> array = indgen(10)
IDL> print, array
0 1 2 3 4 5 6 7 8 9
IDL> print, array[0:-1:2]
0 2 4 6 8
and if you want the even indices (at least, even for those of us that start counting things at one :o),
IDL> print, array[1:-1:2]
1 3 5 7 9
cheers,
paulv
p.s. happy new year btw....
|
|
|
|
|
|
Re: array handling [message #74231 is a reply to message #52128] |
Wed, 05 January 2011 13:30  |
MC
Messages: 50 Registered: September 1996
|
Member |
|
|
On Jan 6, 4:20 am, David Fanning <n...@dfanning.com> wrote:
> David Fanning writes:
>> I think if it averaged the data there would be a
>> decimal point and a .5 in the answer. ;-)
>
>> REBIN always does a /SAMPLE when making the
>> array smaller, by default.
>
> Whoops! A half second after I hit that damn SEND button
> I thought maybe I should just check this out. Of course,
> you are absolutely right, and I am terribly, terribly
> wrong. This is how it's been going for me lately. :-)
>
> Cheers,
> David
>
Your rapid response is one of the reasons why this is still such a
good NG, people readily admit mistakes and others embellish simple
answers with ever increasing sophistication. Wile E. usually falls
into the latter camp!
By the way Happy New Year to All!
Cheers MC
|
|
|
Re: array handling [message #74240 is a reply to message #52128] |
Wed, 05 January 2011 07:20  |
David Fanning
Messages: 11724 Registered: August 2001
|
Senior Member |
|
|
David Fanning writes:
> I think if it averaged the data there would be a
> decimal point and a .5 in the answer. ;-)
>
> REBIN always does a /SAMPLE when making the
> array smaller, by default.
Whoops! A half second after I hit that damn SEND button
I thought maybe I should just check this out. Of course,
you are absolutely right, and I am terribly, terribly
wrong. This is how it's been going for me lately. :-)
Cheers,
David
--
David Fanning, Ph.D.
Fanning Software Consulting, Inc.
Coyote's Guide to IDL Programming: http://www.dfanning.com/
Sepore ma de ni thui. ("Perhaps thou speakest truth.")
|
|
|
Re: array handling [message #74241 is a reply to message #52128] |
Wed, 05 January 2011 07:16  |
David Fanning
Messages: 11724 Registered: August 2001
|
Senior Member |
|
|
MC writes:
> Err, isn't that's going to average the data without the /sample
> keyword?
I think if it averaged the data there would be a
decimal point and a .5 in the answer. ;-)
REBIN always does a /SAMPLE when making the
array smaller, by default.
> As an alternative, how about about using reform:
>
> IDL> array = indgen(10)
> IDL> evenodd=reform(array,2,5)
> IDL> print,"even:" & print,evenodd(0,*)
> IDL> print,"odd:" & print,evenodd(1,*)
>
> As one line:
> print,(reform(array,2,5))(1,*)
There are LOTS of alternatives. This was just
the simplest solution that came to mind. :-)
Cheers,
David
--
David Fanning, Ph.D.
Fanning Software Consulting, Inc.
Coyote's Guide to IDL Programming: http://www.dfanning.com/
Sepore ma de ni thui. ("Perhaps thou speakest truth.")
|
|
|
Re: array handling [message #74242 is a reply to message #74188] |
Wed, 05 January 2011 07:07  |
MC
Messages: 50 Registered: September 1996
|
Member |
|
|
On Jan 4, 7:16 am, David Fanning <n...@dfanning.com> wrote:
> bing999 writes:
>> Thanks for answering. But what I want is to divide the number of
>> elements of my array by 2 by keeping only elements with odd index for
>> instance. Is there an IDL routine which does it?
>
> IDL> array = indgen(10)
> IDL> print, array
> 0 1 2 3 4 5 6 7 8 9
> IDL> print, rebin(array, 5)
> 0 2 4 6 8
>
> Cheers,
>
> David
>
Err, isn't that's going to average the data without the /sample
keyword? As an alternative, how about about using reform:
IDL> array = indgen(10)
IDL> evenodd=reform(array,2,5)
IDL> print,"even:" & print,evenodd(0,*)
IDL> print,"odd:" & print,evenodd(1,*)
As one line:
print,(reform(array,2,5))(1,*)
Cheers MC
|
|
|