[Tutor] Summing arrays

Wolfgang Maier wolfgang.maier at biologie.uni-freiburg.de
Thu Mar 16 05:47:59 EDT 2017

On 03/16/2017 10:38 AM, Wolfgang Maier wrote:
> In addition, I'd agree with Alan that the advantage of using numpy
> functionality in this function seems quite questionable. You'd probably
> get pretty much the same performance with just:
> def sum2(N):
>     return sum(2*(1+3**(i-1)) for i in range(1,N+1,1))

Or, if you really want to leverage the power of numpy (and are willing 
to pay the price of possibly inexact calculations) rewrite your function 
as Peter shows in his reply.

More information about the Tutor mailing list