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

Andreas Perstinger andipersti at gmail.com
Thu Apr 4 16:42:39 CEST 2013


Sayan Chatterjee <sayanchatterjee at 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


More information about the Tutor mailing list