Re: [Tutor] doing maths on lists

2010-12-20 Thread Peter Otten
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

Re: [Tutor] doing maths on lists

2010-12-20 Thread Chris Begert
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/-

Re: [Tutor] doing maths on lists

2010-12-20 Thread Dave Angel
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)+

Re: [Tutor] doing maths on lists

2010-12-20 Thread Steven D'Aprano
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'

Re: [Tutor] doing maths on lists

2010-12-20 Thread Christian Witts
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]

Re: [Tutor] doing maths on lists

2010-12-20 Thread Chris Begert
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 > > > >

Re: [Tutor] doing maths on lists

2010-12-20 Thread Nitin Pawar
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

[Tutor] doing maths on lists

2010-12-20 Thread Chris Begert
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