[Tutor] doing maths on lists

Christian Witts cwitts at compuscan.co.za
Mon Dec 20 12:41:04 CET 2010


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]*cos(L0B[1]+L0C[1]*JME)+...
> + L0A[64]*cos(L0B[64]+L0C[64]*JME)= some float number
>
>
> However, I always get this error:
> 		
> TypeError: can't multiply sequence by non-int of type 'float'				
>
> I looked it up and there seems to be some solution using either the "for-in" command or the "map(int,...)" command but I just can't get it to work....
>
>
> Any help will be very much appreciated :)
>
> Greetings from Sydney
> Chris
>    

Surely it should be
L0 = sum([(L0A[i]*cos(L0B[i]+L0C[i]*JME) for i in range(0, 64)])
as you want to generate the answers and then sum it up.

-- 
Kind Regards,
Christian Witts




More information about the Tutor mailing list