[Tutor] TypeError: can't multiply sequence by non-int of type 'float'

Sayan Chatterjee sayanchatterjee at gmail.com
Thu Apr 4 15:41:21 CEST 2013


I attach the script herewith.


On 4 April 2013 19:10, Sayan Chatterjee <sayanchatterjee at gmail.com> wrote:

> Dear All,
>
> I know this error occurs when one tries to multiply a string with a
> fraction i.e float. In my case , I can't figure out how can a numpy
> floating point array be a string.  Interestingly, the concerned expression
> gets printed in the loop for the first time but on the second go it fails.
>
> The concerned snippet of code is given below :
>
> for t in t_range(0,1,0.1):
>   print t
>   p_za=[]
>   pv_za=[]
>
>   # Opening file in file_t format
>   fname = 'file_' + str(t) + '.dat'
>   fo = open(fname,'w')
>
>   # p_za.append(p_initial - t*K*np.sin(K*p_initial))
>   print 'K=',K
>   print 'pv_za_temp =',pv_za_temp
>   print '- t*K*np.sin(K*p_initial) = ',- t*K*np.sin(K*p_initial)
>   print '-K*np.sin(K*pv_za_temp) = ',-K*np.sin(K*pv_za_temp)
>   pv_za.append(-K*np.sin(K*pv_za_temp))
>   pv_za_temp = []
>   pv_za_temp.append(np.array(pv_za))
>
>
> Here is paste the output,which clearly  shows that the concerned
> expression i.e -K*np.sin(K*pv_za_temp) prints perfectly for the first
> looping. Also see the error that comes on the second looping. I'm clueless.
>
> 0
> K= 3.14159265359
> pv_za_temp = [ 0.   0.5  1.   1.5  2. ]
> - t*K*np.sin(K*p_initial) =  [ 0.  0. -0. -0.  0.]
> *-K*np.sin(K*pv_za_temp) =  [ -0.00000000e+00  -3.14159265e+00
> 6.49753967e-13   3.14159265e+00*
> *  -1.29950793e-12] PRINTS PERFECTLY*
> *
> *
> 0.1
> K= 3.14159265359
> pv_za_temp = [array([[ -0.00000000e+00,  -3.14159265e+00,   6.49753967e-13,
>           3.14159265e+00,  -1.29950793e-12]])]
> - t*K*np.sin(K*p_initial) =  [ -0.00000000e+00  -3.14159265e-01
> 6.49753967e-14   3.14159265e-01
>   -1.29950793e-13]
> -K*np.sin(K*pv_za_temp) = *ERROR*
> Traceback (most recent call last):
>   File "ZA.py", line 45, in <module>
>     print '-K*np.sin(K*pv_za_temp) = ',-K*np.sin(K*pv_za_temp)
> *TypeError: can't multiply sequence by non-int of type 'float'*
>
> Please Help!!!!
>
>
> Cheers,
> Sayan
>
>
> --
>
>
> --------------------------------------------------------------------------
> *Sayan  Chatterjee*
> Dept. of Physics and Meteorology
> IIT Kharagpur
> Lal Bahadur Shastry Hall of Residence
> Room AB 205
> Mob: +91 9874513565
> blog: www.blissprofound.blogspot.com
>
> Volunteer , Padakshep
> www.padakshep.org
>



-- 


--------------------------------------------------------------------------
*Sayan  Chatterjee*
Dept. of Physics and Meteorology
IIT Kharagpur
Lal Bahadur Shastry Hall of Residence
Room AB 205
Mob: +91 9874513565
blog: www.blissprofound.blogspot.com

Volunteer , Padakshep
www.padakshep.org
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20130404/8e20a916/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: ZA.py
Type: application/octet-stream
Size: 2068 bytes
Desc: not available
URL: <http://mail.python.org/pipermail/tutor/attachments/20130404/8e20a916/attachment.obj>


More information about the Tutor mailing list