Re: How to increase the speed [message #85792 is a reply to message #85790] |
Mon, 09 September 2013 07:06  |
sivan
Messages: 13 Registered: August 2012
|
Junior Member |
|
|
Hi Moritz,
Thanks a lot. I really appreciated. Your advise gave me a perfect idea and I solved the problem.
Best wishes,
Sivan.
On Monday, September 9, 2013 1:44:59 PM UTC+3, Moritz Fischer wrote:
> Hi!
>
>
>
> Try the '#' operator (and some algebra to remove the multiplication):
>
>
>
> result = exp( a#replicate(1d,2e5) - replicate(1d,250)#(b-c) )
>
>
>
> You could use reform/rebin with the SAMPLE keyword to do somthing similar.
>
>
>
>
>
> Am 09.09.2013 12:11, schrieb sivan:
>
>> Hello everyone,
>
>>
>
>> I'll directly tell you the problem. I have three arrays, one of them
>
>> contains hundreds of elements, the others have the same number of
>
>> elements and contain much more.
>
>>
>
>> Let say (a is the first, b is the 2nd, and c is the 3rd array)
>
>> a=findgen(250)+1 b=randomn(seed, 2e5) c=randomn(seed, 2e5)
>
>>
>
>> What I want to do is to calculate the following equation for each
>
>> element of a and every element of b and c without using the for
>
>> loop.
>
>>
>
>> exp(a(i) - b)*exp(c)
>
>>
>
>> The result should be a two dimensional array (array[250, 2e5]).
>
>>
>
>> Problem is also shown via this picture
>
>> (http://oi42.tinypic.com/10zcx7p.jpg).
>
>>
>
>> I use the following code but it is very slow.
>
>>
>
>> result=dblarr(250, 2e5) for i=0, 249 do result(i,*)=exp(a(i) -
>
>> b)*exp(c)
>
>>
>
>> Thanks in advice, Sivan.
>
>>
|
|
|