[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

*Subject*: Can I de-loop?*From*: throop(at)colorado.edu*Date*: Thu, 15 Jul 1999 01:42:22 GMT*Newsgroups*: comp.lang.idl-pvwave*Organization*: Deja.com - Share what you know. Learn what you don't.*Xref*: news.doit.wisc.edu comp.lang.idl-pvwave:15679

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.

**Follow-Ups**:**Re: Can I de-loop?***From:*eddie haskell

**Re: Can I de-loop?***From:*R.G. Stockwell

- Prev by Date:
**Eating Humble Pie** - Next by Date:
**Re: Can I de-loop?** - Prev by thread:
**Eating Humble Pie** - Next by thread:
**Re: Can I de-loop?** - Index(es):