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

Home » Public Forums » archive » array handling
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
array handling [message #52128] Sat, 06 January 2007 02:59 Go to next message
jochem.verelst@gmail. is currently offline  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 #74186 is a reply to message #52128] Mon, 03 January 2011 11:50 Go to previous messageGo to next message
natha is currently offline  natha
Messages: 482
Registered: October 2007
Senior Member
And if you don't have IDL 8:

print, array[1:*:2]
Re: array handling [message #74187 is a reply to message #52128] Mon, 03 January 2011 11:10 Go to previous messageGo to next message
Paul Van Delst[1] is currently offline  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 #74188 is a reply to message #52128] Mon, 03 January 2011 10:16 Go to previous messageGo to next message
David Fanning is currently offline  David Fanning
Messages: 11724
Registered: August 2001
Senior Member
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

--
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 #74189 is a reply to message #52128] Mon, 03 January 2011 10:08 Go to previous messageGo to next message
Thibault Garel is currently offline  Thibault Garel
Messages: 55
Registered: October 2009
Member
On Jan 3, 3:04 pm, sirvival <fpfei...@hs.uni-hamburg.de> wrote:
> On 3 Jan., 13:54, bing999 <thibaultga...@gmail.com> wrote:
>
>> Hi,
>
>> In an array, I would like to select only one element over 2 to make a
>> new array. Is there an IDL routine to do it?
>
>> Thanks !
>
> Hi,
> do you mean that you want only values greater than two?
> If so you can use the where command.
>
> pos = where( array gt 2)
> newarry = array[pos]

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?
cheers
Re: array handling [message #74191 is a reply to message #52128] Mon, 03 January 2011 06:04 Go to previous messageGo to next message
sirvival is currently offline  sirvival
Messages: 18
Registered: August 2010
Junior Member
On 3 Jan., 13:54, bing999 <thibaultga...@gmail.com> wrote:
> Hi,
>
> In an array, I would like to select only one element over 2 to make a
> new array. Is there an IDL routine to do it?
>
> Thanks !

Hi,
do you mean that you want only values greater than two?
If so you can use the where command.

pos = where( array gt 2)
newarry = array[pos]
Re: array handling [message #74231 is a reply to message #52128] Wed, 05 January 2011 13:30 Go to previous message
MC is currently offline  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 Go to previous message
David Fanning is currently offline  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 Go to previous message
David Fanning is currently offline  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 Go to previous message
MC is currently offline  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
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: Re: stl files
Next Topic: IDL output directed to STDERR-- can't seem to work around...

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

Current Time: Wed Oct 08 15:16:14 PDT 2025

Total time taken to generate the page: 0.00618 seconds