By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,191 Members | 1,067 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,191 IT Pros & Developers. It's quick & easy.

Python : Having trouble with using the interpolate function

P: 1
Expand|Select|Wrap|Line Numbers
  1.     # Imported array of data from a text file. This code works with no problems.
  2.     q1, a1 = loadtxt("values.txt", unpack = True, skiprows = 1)
  3.     print q1
  4.     print a1
  5.  
  6.     # Creating a while loop for this part of the code. This code works with no problems.
  7.     a = 3
  8.     b = -2
  9.     c = -9
  10.     q = 0.5
  11.     qt = 0.1
  12.  
  13.     while q < 1.5:
  14.         print q, a
  15.         q += qt
  16.         a = a + b*qt
  17.         b = b + c*qt
  18.  
  19.     # This interpolation does not work. I am unable to figure it out.
  20.     # TypeError: object of type 'float' has no len()
  21.  
  22.     from scipy.interpolate import interp1d
  23.     f = interp1d(q,a,'cubic')
  24.     q1 = linspace(0.5,1.4,25)
  25.     a1 = f(q1)
  26.     plot(q1,a1, '-',  q,a, 'o')
  27.     show()
  28.  
  29.  
Thanks.
Sep 20 '14 #1
Share this question for a faster answer!
Share on Google+

Post your reply

Sign in to post your reply or Sign up for a free account.