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

Home » Public Forums » archive » Re: drop array elements
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: drop array elements [message #21461] Fri, 25 August 2000 00:00
Craig Markwardt is currently offline  Craig Markwardt
Messages: 1869
Registered: November 1996
Senior Member
Matthew Kay <mwk@crml.uab.edu> writes:
> Hi,
>
> Would anyone have any suggestions for an easy way
> to drop elements in an array? For example, say 'a'
> is a 14x1024 array and 'b' is a 1x25 array of row
> indicies in 'a' that should be dropped. Is there
> a simple command for re-assigning 'a', without the
> 25 rows indicated in 'b'?

The best way to go after this is to rephrase the question so that BP
(b-primed) is the list of rows to *keep*. Then it's easy:

a = a(*,bp)

This, in the end, is what JD was getting after. A way to see this
more clearly might be to do it in steps like this:

tmp = intarr(1024) + 1 ;; Create a mask with all 1's by default
tmp(b) = 0 ;; Zero out the discarded rows
bp = where(tmp EQ 1, ct) ;; Find the kept rows - compute BP
if ct GT 0 then a = a(*,bp) ;; Extract those rows

Good luck,
Craig

--
------------------------------------------------------------ --------------
Craig B. Markwardt, Ph.D. EMAIL: craigmnet@cow.physics.wisc.edu
Astrophysics, IDL, Finance, Derivatives | Remove "net" for better response
------------------------------------------------------------ --------------
Re: drop array elements [message #21463 is a reply to message #21461] Fri, 25 August 2000 00:00 Go to previous message
davidf is currently offline  davidf
Messages: 2866
Registered: September 1996
Senior Member
Liam E. Gumley (Liam.Gumley@ssec.wisc.edu) writes:

> I just *had* to understand this one. Here's another way of implementing
> this method:
>
> ;- Get number of rows in a
> dims = (size(a, /dimensions))[1]
>
> ;- Create index array for rows of a (1=keep the row, 0=discard the row)
> index = replicate(1L, nrows)
> index[b] = 0L
>
> ;- Locate the indices of rows we wish to keep
> keep = where(index eq 1)
>
> ;- Extract the rows we wish to keep
> a = (temporary(a))[*, keep]

I think JD *must* have thought about the program
like this first. (I mean, he is flesh and bones,
right!?) He then just jammed it all together like
he did to scare anyone else thinking about taking
the IDL EPA exam.

Cheers,

David

P.S. Let's just say I'm glad I'm not up for
re-certification for another two years. :-(

--
David Fanning, Ph.D.
Fanning Software Consulting
Phone: 970-221-0438 E-Mail: davidf@dfanning.com
Coyote's Guide to IDL Programming: http://www.dfanning.com/
Toll-Free IDL Book Orders: 1-888-461-0155
Re: drop array elements [message #21464 is a reply to message #21461] Fri, 25 August 2000 00:00 Go to previous message
Liam E. Gumley is currently offline  Liam E. Gumley
Messages: 378
Registered: January 2000
Senior Member
"J.D. Smith" wrote:
>
> Matthew Kay wrote:
>>
>> Would anyone have any suggestions for an easy way
>> to drop elements in an array? For example, say 'a'
>> is a 14x1024 array and 'b' is a 1x25 array of row
>> indicies in 'a' that should be dropped. Is there
>> a simple command for re-assigning 'a', without the
>> 25 rows indicated in 'b'?
>>
> a=a[*,where(histogram(b,MIN=0,MAX=(size(a,/DIMENSIONS))[1]-1 ,BINSIZE=1) eq 0)]
>
> The real meat here is finding a list of indices which do not contain the
> elements of b. There are many ways to do this, but this is a fast one.

I just *had* to understand this one. Here's another way of implementing
this method:

;- Get number of rows in a
dims = (size(a, /dimensions))[1]

;- Create index array for rows of a (1=keep the row, 0=discard the row)
index = replicate(1L, nrows)
index[b] = 0L

;- Locate the indices of rows we wish to keep
keep = where(index eq 1)

;- Extract the rows we wish to keep
a = (temporary(a))[*, keep]

Cheers,
Liam.
http://cimss.ssec.wisc.edu/~gumley
Re: drop array elements [message #21470 is a reply to message #21461] Fri, 25 August 2000 00:00 Go to previous message
davidf is currently offline  davidf
Messages: 2866
Registered: September 1996
Senior Member
J.D. Smith (jdsmith@astro.cornell.edu) writes:

> a=a[*,where(histogram(b,MIN=0,MAX=(size(a,/DIMENSIONS))[1]-1 ,BINSIZE=1) eq 0)]

I've been thinking of retiring so I can play more tennis. :-(

Cheers,

David

--
David Fanning, Ph.D.
Fanning Software Consulting
Phone: 970-221-0438 E-Mail: davidf@dfanning.com
Coyote's Guide to IDL Programming: http://www.dfanning.com/
Toll-Free IDL Book Orders: 1-888-461-0155
Re: drop array elements [message #21471 is a reply to message #21461] Fri, 25 August 2000 00:00 Go to previous message
John-David T. Smith is currently offline  John-David T. Smith
Messages: 384
Registered: January 2000
Senior Member
Matthew Kay wrote:
>
> Hi,
>
> Would anyone have any suggestions for an easy way
> to drop elements in an array? For example, say 'a'
> is a 14x1024 array and 'b' is a 1x25 array of row
> indicies in 'a' that should be dropped. Is there
> a simple command for re-assigning 'a', without the
> 25 rows indicated in 'b'?
>
> Much thanks,
> Matt

a=a[*,where(histogram(b,MIN=0,MAX=(size(a,/DIMENSIONS))[1]-1 ,BINSIZE=1) eq 0)]

The real meat here is finding a list of indices which do not contain the
elements of b. There are many ways to do this, but this is a fast one.

JD

--
J.D. Smith /*\ WORK: (607) 255-6263
Cornell University Dept. of Astronomy \*/ (607) 255-5842
304 Space Sciences Bldg. /*\ FAX: (607) 255-5875
Ithaca, NY 14853 \*/
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: Re: PV-WAVE Runtime Mode Balks
Next Topic: PV-WAVE Runtime Mode Balks

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

Current Time: Fri Oct 10 11:26:20 PDT 2025

Total time taken to generate the page: 0.00925 seconds