I'm stumbled into the same error over and over again. I define multiple functions but I'm having trouble with this part:
a = 50000.0
c = 1.0
def fkt(smatrix, a, c):
y_Dach = [0.] * 93
for i in range(0, 93):
y_Dach[i] = c*( 1.5*(smatrix[i])/a -
0.5*((smatrix[i])/a)**3.0 )
return y_Dach
So smatrix is a list with 93 floats - 1 dimensional, which is proven by the fact that I tried recalling it and the type with print smatrix[0] and print type(smatrix[0]) inside the function already - and it works as expected.
My problem is that I keep gettin this error:
Traceback (most recent call last):
File "bla.py", line 260, in <module>
print anneal(fkt, a, c, bmatrix)
File "bla.py", line 242, in anneal
fkt(smatrix, a, c)
File "bla.py", line 220, in fkt
y_Dach[i] = c*( 1.5*(smatrix[i])/a -
0.5*((smatrix[i])/a)**3.0 )
TypeError: can't multiply sequence by non-int of type 'float'
I literally tried everything my little programming skills can do to fix that, but I can't get rid of the error, it keeps reappearing. Why I can't calculate with only floats inside my list?
I'm pretty new to programming but i try everything to learn more at the moment. I hope I can reply correct to your request, if not let me know.
@Anand S Kumar when i call smatrix by print smatrix[0] it will show 2500.0 , when i do print smatrix it will show:
[2500.0, 3500.0, 5500.0, 6500.0, 7500.0, 8500.0, 9500.0, 10500.0,
11500.0, 12500.0, 13500.0, 14500.0, 15500.0, 16500.0,
17500.0, 18500.0, 19500.0, 20500.0, 21500.0, 22500.0, 23500.0, 24500.0,
25500.0, 26500.0, 27500.0, 28500.0, 29500.0, 30500.0, 31500.0, 32500.0,
33500.0, 34500.0, 35500.0, 36500.0, 37500.0, 38500.0, 39500.0, 40500.0,
41500.0, 42500.0, 43500.0, 44500.0, 45500.0, 46500.0, 47500.0, 48500.0,
49500.0, 50500.0, 51500.0, 52500.0, 53500.0, 54500.0, 55500.0, 56500.0,
57500.0, 58500.0, 59500.0, 60500.0, 61500.0, 62500.0, 63500.0, 64500.0,
65500.0, 66500.0, 67500.0, 68500.0, 69500.0, 70500.0, 71500.0, 72500.0,
73500.0, 74500.0, 75500.0, 76500.0, 78500.0, 79500.0, 80500.0, 81500.0,
83500.0, 85500.0, 87500.0, 88500.0, 89500.0, 90500.0, 91500.0, 92500.0,
93500.0, 95500.0, 98500.0, 99500.0, 100500.0, 103500.0, 107500.0]
[0. for j in range (93)]can be written shorter as[0] * 93*/smatrix=[1.0,2.0,3.0]and the expression evaluated without error.