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

Home » Public Forums » archive » Can I de-loop?
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Return to the default flat view Create a new topic Submit Reply
Can I de-loop? [message #16309] Thu, 15 July 1999 00:00 Go to previous message
throop is currently offline  throop
Messages: 8
Registered: August 1998
Junior Member
OK, I'm trying to remove the loops in two IDL routines, and I
can't come up with good methods for either. Thought I'd ask for
suggestions in case I'm missing the obvious.

a) I am adding a constant amount K to several elements N of array A.
The elements Ni are not unique; if an Ni is repeated, I want to add it
to A each time. For instance, given

A = [0,1,2]
N = [2,2,2]
K = 4

I want the result A = [0,1,14], not A = [0,1,6]

The obvious solution is

A[N] = A[N] + K

However, this doesn't work if Ni appears multiple times in N. Using a
loop does the job correctly, but is several times slower:

for i = 0, n_elements(N)-1 do A[N[i]] = A[N[i]] - K

b) I'm looking for a general `outer product' routine that operates on
arrays in the same way IDL's # operator will take the outer product of
two vectors. What I want is a function that's passed N- &
M-dimensional arrays, and returns an N+M-dimensional result, which
contains every pairwise combination of products.

It's easy enough to do this using nested loops. Is it possible to do
it without loops, even for small dimensions (e.g., N=1, M=2)?

thanks,

-henry

------------------------------------------------------------
| Henry Throop throop@broccoli.colorado.edu (303) 492-1628 |
------------------------------------------------------------
| Laboratory for Atmospheric and Space Physics |
| University of Colorado, Boulder 80309-0392 |
------------------------------------------------------------


Sent via Deja.com http://www.deja.com/
Share what you know. Learn what you don't.
[Message index]
 
Read Message
Read Message
Previous Topic: Transparent polygon object?
Next Topic: Remapping into another projection

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

Current Time: Wed Oct 08 17:01:08 PDT 2025

Total time taken to generate the page: 0.00339 seconds