Python:使用插值函数有问题

选择 | 换行 | 行号
  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.  

谢谢

标签: python

添加新评论