let me just post my code:<br><br>t is the time array and n is also an array. <br><br>For every value of time t, these operations are performed on the entire array n. Then, n is summed to a scalar which represents the system response at time t. <br>
<br>I would like to eliminate this for loop if possible. <br><br>Chris<br><br>#### code ####<br><br>b = 4.7    <br>f = []<br>n = arange(1, N+1, 1)<br><br>for t in timearray:<br>        arg1 = {'S': ((b/t) + (1J*n*pi/t))}<br>
        exec('from numpy import *', arg1)<br>        tempval = eval(transform, arg1)*((-1)**n)<br>        rsum = tempval.real.sum()<br>        arg2 = {'S': b/t}<br>        exec('from numpy import *', arg2)<br>
        tempval2 = eval(transform, arg2)*0.5<br>        fval = (exp(b) / t) * (tempval2 + rsum)<br>        f.append(fval)<br><br><br>#### /code #####<br><br><br><br><div class="gmail_quote">On Thu, May 7, 2009 at 1:04 PM, Chris Colbert <span dir="ltr"><<a href="mailto:sccolbert@gmail.com">sccolbert@gmail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">unfortunately, the actual function being processes is not so simple, and involves evaluating user functions input from the prompt as strings. So i have no idea how to do it in Cython. <br>
<br>Let me look into this broadcasting. <br>
<br>Thanks Josef!<div><div></div><div class="h5"><br><br><div class="gmail_quote">On Thu, May 7, 2009 at 12:56 PM,  <span dir="ltr"><<a href="mailto:josef.pktd@gmail.com" target="_blank">josef.pktd@gmail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
<div><div></div><div>On Thu, May 7, 2009 at 12:39 PM, Chris Colbert <<a href="mailto:sccolbert@gmail.com" target="_blank">sccolbert@gmail.com</a>> wrote:<br>
> suppose i have two arrays:  n and t, both are 1-D arrays.<br>
><br>
> for each value in t, I need to use it to perform an element wise scalar<br>
> operation on every value in n and then sum the results into a single scalar<br>
> to be stored in the output array.<br>
><br>
> Is there any way to do this without the for loop like below:<br>
><br>
> for val in t_array:<br>
><br>
>           out = (n / val).sum()  # not the actual function being done, but<br>
> you get the idea<br>
><br>
<br>
<br>
</div></div>broad casting should work, e.g.<br>
<br>
(n[:,np.newaxis] / val[np.newaxis,:]).sum()<br>
<br>
but it constructs the full product array, which is memory intensive<br>
for a reduce operation, if the 1d arrays are large.<br>
<br>
another candidate for a cython loop if the arrays are large?<br>
<br>
Josef<br>
_______________________________________________<br>
Numpy-discussion mailing list<br>
<a href="mailto:Numpy-discussion@scipy.org" target="_blank">Numpy-discussion@scipy.org</a><br>
<a href="http://mail.scipy.org/mailman/listinfo/numpy-discussion" target="_blank">http://mail.scipy.org/mailman/listinfo/numpy-discussion</a><br>
</blockquote></div><br>
</div></div></blockquote></div><br>