开发者

Python and Scipy programming

开发者 https://www.devze.com 2023-04-12 23:47 出处:网络
I\'m getting this error message: Traceback (most recent call last): File \"C:/Python27/test\", line 14, in <module>

I'm getting this error message:

Traceback (most recent call last):
  File "C:/Python27/test", line 14, in <module>
    tck = interpolate.bisplrep(X,Y,Z)
  File "C:\Python27\lib\site-packages\scipy\interpolate\fitpack.py", line 850, in bisplrep
    raise TypeError('m >= (kx+1)(ky+1) must hold')
TypeError: m >= (kx+1)(ky开发者_JAVA技巧+1) must hold

The error says that len(X) = m is <=(kx+1)(ky+1). How can I solve this? Here's my program:

import scipy
import math
import numpy
from scipy import interpolate


x= [1000,2000,3000,4000,5000,6000]
y= [1000]

Y = numpy.array([[i]*len(x) for i in y])
X = numpy.array([x for i in y])
Z = numpy.array([[21284473.74,2574509.71,453334.97,95761.64,30580.45,25580.60]]) 

tck = interpolate.bisplrep(x,y,Z)
print interpolate.bisplev(3500,1000,tck) 


Have you read the documentation?

If you don't specify kx and ky, default values will be 3:

scipy.interpolate.bisplrep(x, y, z, w=None, xb=None, xe=None, yb=None, ye=None, 
                           kx=3, ky=3, task=0, s=None, eps=1e-16, tx=None, ty=None,
                           full_output=0, nxest=None, nyest=None, quiet=1)

And of course, len(X) = 6 < 16 = (3+1)(3+1).

Even if you give kx=1 and ky=1 explicitly while calling, you have another problem. Your (x,y) values form a line, and you can not define a surface from a line. Therefore it gives you ValueError: Invalid inputs.. First, you should fix your data. If this is your data, as you have no variation in Y, skip it and do a spline in 2D with X and Z.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号