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

2013-04-05 Thread Sayan Chatterjee
Thanks all...I realized my mistake!!...:)


On 4 April 2013 20:12, Andreas Perstinger andiper...@gmail.com wrote:

 Sayan Chatterjee sayanchatter...@gmail.com wrote:

 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.

 The problem is not that the numpy array is a string but that you append
 the array to a python list:

   pv_za=[]
   pv_za.append(-K*np.sin(K*pv_za_temp))
   pv_za_temp = []
   pv_za_temp.append(np.array(pv_za))

 Both pv_za and pv_za_temp are python lists to which you append a
 numpy array. But since you delete both lists in each iteration I assume
 you want to just assign a new numpy array to both names:

 pv_za = -K * np.sin(K * pv_za_temp)
 pv_za_temp = pv_za # pv_za is already a numpy array

 Bye, Andreas
 ___
 Tutor maillist  -  Tutor@python.org
 To unsubscribe or change subscription options:
 http://mail.python.org/mailman/listinfo/tutor




-- 


--
*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
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


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

2013-04-04 Thread Sayan Chatterjee
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.e+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.e+00,  -3.14159265e+00,   6.49753967e-13,
  3.14159265e+00,  -1.29950793e-12]])]
- t*K*np.sin(K*p_initial) =  [ -0.e+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
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


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

2013-04-04 Thread Sayan Chatterjee
I attach the script herewith.


On 4 April 2013 19:10, Sayan Chatterjee sayanchatter...@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.e+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.e+00,  -3.14159265e+00,   6.49753967e-13,
   3.14159265e+00,  -1.29950793e-12]])]
 - t*K*np.sin(K*p_initial) =  [ -0.e+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


ZA.py
Description: Binary data
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


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

2013-04-04 Thread Oscar Benjamin
On 4 April 2013 14:40, Sayan Chatterjee sayanchatter...@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

K is somewhere above set to a float with the value 3.14...

   print 'pv_za_temp =',pv_za_temp

pv_za_temp is somewhere above set to a list containing an array as
it's only element.

   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)

Here you try to multiply the two. The error can be achieved like so:

 import numpy
 a = numpy.array([[1, 2], [3, 4]])
 a
array([[1, 2],
   [3, 4]])
 3.14 * a
array([[  3.14,   6.28],
   [  9.42,  12.56]])
 3.14 * [a]

Perhaps what you want is to multiply K with pv_za_temp[0]?

[SNIP]
 K= 3.14159265359
 pv_za_temp = [array([[ -0.e+00,  -3.14159265e+00,   6.49753967e-13,
   3.14159265e+00,  -1.29950793e-12]])]


Oscar
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


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

2013-04-04 Thread Andreas Perstinger
Sayan Chatterjee sayanchatter...@gmail.com wrote:

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.

The problem is not that the numpy array is a string but that you append
the array to a python list:

  pv_za=[]
  pv_za.append(-K*np.sin(K*pv_za_temp))
  pv_za_temp = []
  pv_za_temp.append(np.array(pv_za))

Both pv_za and pv_za_temp are python lists to which you append a
numpy array. But since you delete both lists in each iteration I assume
you want to just assign a new numpy array to both names:

pv_za = -K * np.sin(K * pv_za_temp)
pv_za_temp = pv_za # pv_za is already a numpy array

Bye, Andreas
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor