>def sum2(N):
>b = np.arange(1,N+1,1)
> mylist = [ ]
> for i in b:
>terms = 2*(1+3**(i-1))
> a = mylist.append[terms]
> return np.sum(mylist)
>print(sum2(N=50))
You have an error such as:
a = mylist.append(terms)
___
Tutor m
Peter Otten wrote:
> (Specifying dtype=float forces floating point arithmetic which is inexact)
I found a way to avoid the error:
>>> import numpy as np
>>> def sum2(N):
... a = np.arange(1, N+1, dtype=object)
... return (2*(1+3**(a-1))).sum()
...
>>> sum2(50)
717897987691852588770348
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+
On 03/16/2017 10:12 AM, Alan Gauld via Tutor wrote:
On 16/03/17 05:11, Aaliyah Ebrahim wrote:
def sum2(N):
b = np.arange(1,N+1,1)
mylist = [ ]
for i in b:
terms = 2*(1+3**(i-1))
a = mylist.append[terms]
return np.sum(mylist)
terms = 2*(1+3**(i-1))> 9
Aaliyah Ebrahim wrote:
> Hi guys! I hope you can assist me with understanding and fixing my error
> below. Thanks for this amazing forum :)
>
>
> def sum2(N):
>
> b = np.arange(1,N+1,1)
> mylist = [ ]
> for i in b:
>
>
> terms = 2*(1+3**(i-1))
> a = mylist.append[t
On 16/03/17 05:11, Aaliyah Ebrahim wrote:
> def sum2(N):
>
> b = np.arange(1,N+1,1)
> mylist = [ ]
> for i in b:
> terms = 2*(1+3**(i-1))
> a = mylist.append[terms]
> return np.sum(mylist)
> terms = 2*(1+3**(i-1))> 9 mylist.append[terms] 10
> retur
Hi guys! I hope you can assist me with understanding and fixing my error
below. Thanks for this amazing forum :)
def sum2(N):
b = np.arange(1,N+1,1)
mylist = [ ]
for i in b:
terms = 2*(1+3**(i-1))
a = mylist.append[terms]
return np.sum(mylist)
print(sum2(N=50))