Click here to Skip to main content
15,896,154 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Python
# Imported array of data from a text file. This code works with no problems.
q1, a1 = loadtxt("values.txt", unpack = True, skiprows = 1)
print q1
print a1

# Creating a while loop for this part of the code. This code works with no problems.
a = 3
b = -2
c = -9
q = 0.5
qt = 0.1

while q < 1.5:
    print q, a
    q += qt
    a = a + b*qt
    b = b + c*qt

# This interpolation does not work. I am unable to figure it out.
# TypeError: object of type 'float' has no len()

from scipy.interpolate import interp1d
f = interp1d(q,a,'cubic')
q1 = linspace(0.5,1.4,25)
a1 = f(q1)
plot(q1,a1, '-',  q,a, 'o')
show()


Thanks.
Posted
Comments
Sergey Alexandrovich Kryukov 20-Sep-14 12:09pm    
"Having trouble", "does not work" and "I am unable to figure out" is not informative.
In your code shown, there is no a call to float.len(); it's somewhere else. Locate it.
—SA

1 solution

The issue is that interp1d expects arrays (or array like values), and both q and a are plain floats. For the function to work you also need at least two elements in the array.
I've not used scipy and I'm not sure what your intent is so I can't offer an exact solution, but that's where your type error is coming from.
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900