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

Home » Public Forums » archive » Deleting from arrays
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Return to the default flat view Create a new topic Submit Reply
Deleting from arrays [message #31238] Thu, 27 June 2002 07:54
Randall Skelton is currently offline  Randall Skelton
Messages: 169
Registered: October 2000
Senior Member
Many thanks to Dick and Reimar for there excellent suggestions regarding
concatenating arrays. My next question is, does anyone have code for
removing data from a general (i.e. up to 8 dimensional) array? Imagine
trying to remove the data marked by an asterisks '*'

In the 1D case:

* * * *
[ 0 1 2 3 4 5 6 7 8 9 ] -> result is a vector: [ 0 1 6 7 8 9 ]

In the 2D case:

* *
a b c d e f g c d e f g
* h i j k l m n -> result is a matrix: q r s t u
o p q r s t u

I know that Craig has code for cleverly doing the 1D case, but I'm
looking to do this for at least up to 4D. I'm willing to accept that it
is probably easier to do n-dimensional deletion with n separate steps.
So, in the 2D case above I would first remove the dimension 0
elements (columns) followed by removing the dimension 1 elements (rows).

Something like:

; 2D case
a = [[0,1,2,3,4], [5,6,7,8,9], [10,11,12,13,14]]
idx = [2,3,4] ; indicies to keep in dim 0
a = temporary( a[idx,*] )
idx = [0,2] ; indicies to keep in dim 1
a = temporary( a[*,idx] )

; 3D case
a = [[[0,1,2,3,4], [5,6,7,8,9], [10,11,12,13,14]],$
[[15,16,17,18,19], [20,21,22,23,24], [25,26,27,28,29]],$
[[30,31,32,33,34],[35,36,37,38,39],[40,41,42,43,44]]]
idx = [2,3,4] ; indicies to keep in dim 0
a = temporary( a[idx,*,*] )
idx = [0,2] ; indicies to keep in dim 1
a = temporary( a[*,idx,*] )
idx = [1,2] ; indicies to keep in dim 2
a = temporary( a[*,*,idx] )

If anyone has any ideas on how to generalize this, I'd be keen to hear
them. At the moment, I calculate the indicies of the elements I wish to
keep and use different cases depending on the dimension I want to remove.

case dim of
0: a = temporary( a[idx,*,*,*,*,*,*,*] )
1: a = temporary( a[*,idx,*,*,*,*,*,*] )
2: a = temporary( a[*,*,idx,*,*,*,*,*] )
...
endcase

Cheers,
Randall

PS: I am waiting for someone to post the solution as an IDL 'one-liner' ;)
[Message index]
 
Read Message
Previous Topic: 24 bit display problems
Next Topic: Re: Limiting concatenation IDL 5.5

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

Current Time: Sat Oct 11 11:00:48 PDT 2025

Total time taken to generate the page: 0.02618 seconds