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
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 =
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
>
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)
d
array([[0, 0, 1],
[1, 2, 3],
[2, 2, 4],
[3, 6, 8]])
e=reshape((d[:,-2]+d[:,-1]),(4,1))
e
array([[ 1],
[ 5],
[ 6],
[14]])
is there a better way to accomplish this?
___
Tutor maillist - Tutor@python.org
John wrote:
d
array([[0, 0, 1],
[1, 2, 3],
[2, 2, 4],
[3, 6, 8]])
e=reshape((d[:,-2]+d[:,-1]),(4,1))
e
array([[ 1],
[ 5],
[ 6],
[14]])
is there a better way to accomplish this?
d
[[0, 0, 1], [1, 2, 3], [2, 2, 4], [3, 6, 8]]
e = [sum(i)
John [EMAIL PROTECTED] wrote
d
array([[0, 0, 1],
[1, 2, 3],
[2, 2, 4],
[3, 6, 8]])
e=reshape((d[:,-2]+d[:,-1]),(4,1))
e
array([[ 1],
[ 5],
[ 6],
[14]])
is there a better way to accomplish this?
Better? Maybe. More readable I think is:
e1 = [
John wrote:
d
array([[0, 0, 1],
[1, 2, 3],
[2, 2, 4],
[3, 6, 8]])
e=reshape((d[:,-2]+d[:,-1]),(4,1))
e
array([[ 1],
[ 5],
[ 6],
[14]])
is there a better way to accomplish this?
Which module are you using?
In APL we'd write +/d to reduce
10 matches
Mail list logo