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

Home » Public Forums » archive » Re: array addressing
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: array addressing [message #2514] Tue, 02 August 1994 02:44
sjt is currently offline  sjt
Messages: 72
Registered: November 1993
Member
Terry Kucera (kucera@stars.gsfc.nasa.gov) wrote:
: In article <CtvMnL.MAD@hpl.hp.com>, peter@hpl.hp.com (Peter Webb) writes...
: >William Thompson (thompson@orpheus.gsfc.nasa.gov) wrote:
: >: kump@morph.ebme.cwru.edu (Kenneth S. Kump) writes:
: >
: >: >Just a quick question:
: >
: >: >A=indarr(10,5)
: >: >B=[0,0,1,0,1]
: >
: >
: >: >I would like array C to consist of only A(*,2) and A(*,4).
: >: >I understand why C=A(*,B) doesn't work, but what is the
: >: >correct way?
: >
: >: Just thinking off the top of my head, one could do something like the
: >: following:
: >
: >: IDL> SZ = SIZE(A) ;Get dimensions of A
: >: IDL> BB = REPLICATE(1,SZ(1)) # B ;Match dims. of B to A
: >: IDL> C = A(WHERE(BB EQ 1)) ;Extract requested data
: >: IDL> C = REFORM(C,SZ(1),TOTAL(B)) ;Rectify dimensions
: >
: >: I haven't actually tried this to confirm that it works, but I think it will.
: >: :^)
: >
: >: Bill Thompson
: >
: >Or, c=a(*,[2,4]) might be a bit easier...

: Or, c=a(*,where(b)) if you don't know b ahead of time.
: Terry Kucera

maybe for safety you might be better with:

locs=where(b,nl)
if (nl ne 0) then c=a(*,locs)

to avoid the risk of having effectively c=a(*,-1) which will crash your
program.

--
James Tappin, School of Physics & Space Research
University of Birmingham
sjt@xun8.sr.bham.ac.uk
"If all else fails--read the instructions!"

O__
-- \/`
Re: array addressing [message #2516 is a reply to message #2514] Mon, 01 August 1994 16:49 Go to previous message
kucera is currently offline  kucera
Messages: 7
Registered: June 1994
Junior Member
In article <CtvMnL.MAD@hpl.hp.com>, peter@hpl.hp.com (Peter Webb) writes...
> William Thompson (thompson@orpheus.gsfc.nasa.gov) wrote:
> : kump@morph.ebme.cwru.edu (Kenneth S. Kump) writes:
>
> : >Just a quick question:
>
> : >A=indarr(10,5)
> : >B=[0,0,1,0,1]
>
>
> : >I would like array C to consist of only A(*,2) and A(*,4).
> : >I understand why C=A(*,B) doesn't work, but what is the
> : >correct way?
>
> : Just thinking off the top of my head, one could do something like the
> : following:
>
> : IDL> SZ = SIZE(A) ;Get dimensions of A
> : IDL> BB = REPLICATE(1,SZ(1)) # B ;Match dims. of B to A
> : IDL> C = A(WHERE(BB EQ 1)) ;Extract requested data
> : IDL> C = REFORM(C,SZ(1),TOTAL(B)) ;Rectify dimensions
>
> : I haven't actually tried this to confirm that it works, but I think it will.
> : :^)
>
> : Bill Thompson
>
> Or, c=a(*,[2,4]) might be a bit easier...

Or, c=a(*,where(b)) if you don't know b ahead of time.
Terry Kucera
Re: array addressing [message #2517 is a reply to message #2516] Mon, 01 August 1994 15:04 Go to previous message
peter is currently offline  peter
Messages: 80
Registered: February 1994
Member
William Thompson (thompson@orpheus.gsfc.nasa.gov) wrote:
: kump@morph.ebme.cwru.edu (Kenneth S. Kump) writes:

: >Just a quick question:

: >A=indarr(10,5)
: >B=[0,0,1,0,1]


: >I would like array C to consist of only A(*,2) and A(*,4).
: >I understand why C=A(*,B) doesn't work, but what is the
: >correct way?

: Just thinking off the top of my head, one could do something like the
: following:

: IDL> SZ = SIZE(A) ;Get dimensions of A
: IDL> BB = REPLICATE(1,SZ(1)) # B ;Match dims. of B to A
: IDL> C = A(WHERE(BB EQ 1)) ;Extract requested data
: IDL> C = REFORM(C,SZ(1),TOTAL(B)) ;Rectify dimensions

: I haven't actually tried this to confirm that it works, but I think it will.
: :^)

: Bill Thompson

Or, c=a(*,[2,4]) might be a bit easier...
Re: array addressing [message #2518 is a reply to message #2517] Mon, 01 August 1994 14:06 Go to previous message
thompson is currently offline  thompson
Messages: 584
Registered: August 1991
Senior Member
kump@morph.ebme.cwru.edu (Kenneth S. Kump) writes:

> Just a quick question:

> A=indarr(10,5)
> B=[0,0,1,0,1]


> I would like array C to consist of only A(*,2) and A(*,4).
> I understand why C=A(*,B) doesn't work, but what is the
> correct way?

Just thinking off the top of my head, one could do something like the
following:

IDL> SZ = SIZE(A) ;Get dimensions of A
IDL> BB = REPLICATE(1,SZ(1)) # B ;Match dims. of B to A
IDL> C = A(WHERE(BB EQ 1)) ;Extract requested data
IDL> C = REFORM(C,SZ(1),TOTAL(B)) ;Rectify dimensions

I haven't actually tried this to confirm that it works, but I think it will.
:^)

Bill Thompson
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: Bug in formatted read?
Next Topic: Re: convert 4 bytes into a long

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

Current Time: Wed Oct 08 19:14:22 PDT 2025

Total time taken to generate the page: 0.00650 seconds