# Re: Can I de-loop?

• Subject: Re: Can I de-loop?
• Date: Thu, 15 Jul 1999 09:14:54 -0400
• Newsgroups: comp.lang.idl-pvwave
• Organization: Old Dominion Universityaruba
• References: <7mje9s\$263\$1@nnrp1.deja.com>
• Xref: news.doit.wisc.edu comp.lang.idl-pvwave:15685

```I have a suggestion for the first of your quandries:

> 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]

IDL> A[min(N):max(N)] = A[min(N):max(N)] + K*histogram(N)
IDL> print,A
0       1      14

This seems to be at least twice as fast as the loop with the time
difference increasing as the number of elements in A and N increase, at
least for the values I played around with ( up to 100,000 elements).

You should check this thread later as I should point out that over 95%
of my suggestions to this newsgroup do not end up helping the original
question.  Either my solution is too specific for the problem or someone
else soon posts a better solution.  I hope for the latter as I can also
learn something that way.

Cheers,
eddie

----- ---- --- ---  ---- --- --  --- --- --  -- - -  -  -