Dave Angel wrote:
> from math import cos
>
> JME = 0.4
> L0A = [2.3, 4.65]
> L0B = [1.8, 2.2]
> L0C = [12.1, 4]
> limit = len(L0A)
>
> L0 = sum(L0A[i]*cos(L0B[i]+L0C[i]*JME) for i in range(limit))
OP, if you are planning to do this "maths on lists" a lot you should have a
look at numpy. With n
Dave and Christian
Thanks a lot for the help, it looks like it works!
Chris
Original-Nachricht
> Datum: Mon, 20 Dec 2010 07:32:45 -0500
> Von: Dave Angel
> An: Chris Begert
> CC: tutor@python.org
> Betreff: Re: [Tutor] doing maths on lists
> On 01/-
On 01/-10/-28163 02:59 PM, Chris Begert wrote:
Bonjour
I have three lists with 65 float items and would like to do the following sum:
L0 = ([sum(L0A[i]*cos(L0B[i]+L0C[i]*JME) for i in range(0,64,1))])
So it just should do a sum across all the items in the list:
L0A[0]*cos(L0B[0]+L0C[0]*JME)+
Chris Begert wrote:
Bonjour
I have three lists with 65 float items and would like to do the following sum:
L0 = ([sum(L0A[i]*cos(L0B[i]+L0C[i]*JME) for i in range(0,64,1))])
[...]
However, I always get this error:
TypeError: can't multiply sequence by non-int of type 'float'
On 20/12/2010 12:58, Chris Begert wrote:
Bonjour
I have three lists with 65 float items and would like to do the following sum:
L0 = ([sum(L0A[i]*cos(L0B[i]+L0C[i]*JME) for i in range(0,64,1))])
So it just should do a sum across all the items in the list:
L0A[0]*cos(L0B[0]+L0C[0]*JME)+ L0A[1]
t
> CC: tutor@python.org
> Betreff: Re: [Tutor] doing maths on lists
> you may want to do type casting whenever you have a float answer cause
> integer to float causes data loss
>
> On Mon, Dec 20, 2010 at 4:28 PM, Chris Begert wrote:
>
> > Bonjour
> >
> >
you may want to do type casting whenever you have a float answer cause
integer to float causes data loss
On Mon, Dec 20, 2010 at 4:28 PM, Chris Begert wrote:
> Bonjour
>
> I have three lists with 65 float items and would like to do the following
> sum:
>
> L0 = ([sum(L0A[i]*cos(L0B[i]+L0C[i]*JME
Bonjour
I have three lists with 65 float items and would like to do the following sum:
L0 = ([sum(L0A[i]*cos(L0B[i]+L0C[i]*JME) for i in range(0,64,1))])
So it just should do a sum across all the items in the list:
L0A[0]*cos(L0B[0]+L0C[0]*JME)+ L0A[1]*cos(L0B[1]+L0C[1]*JME)+...
+ L0A[64]*cos(L