[SciPy-User] SmoothBivariateSpline giving wrong result
josef.pktd@gmai...
josef.pktd@gmai...
Tue Oct 16 18:39:42 CDT 2012
On Tue, Oct 16, 2012 at 7:32 PM, <josef.pktd@gmail.com> wrote:
> On Mon, Oct 15, 2012 at 11:19 PM, Kevin Gullikson
> <kevin.gullikson@gmail.com> wrote:
>> Hi all,
>>
>> I am trying to do a 2d interpolation of unstructured data. To try to get a
>> feel for how the functions work, I tried a simple test case and it is not
>> working. See below:
>>
>> In [24]: x = numpy.arange(10.)
>>
>> In [25]: y = numpy.arange(10.)
>>
>> In [26]: z = x**2 + y**2
>>
>> In [27]: fcn = SmoothBivariateSpline(x,y,z, s=0, kx=1, ky=1)
>>
>> In [28]: fcn(1,1)
>> Out[28]: array([[ 0.]])
>>
>> In [29]: fcn(1,5)
>> Out[29]: array([[ 0.]])
>>
>>
>> What am I doing wrong? It seems like z should be a 2d array or something,
>> but the documentation explicitly says it is a 1d array.
>
> 1d is fine but you need points that cover an area in R^2 not just a
> line, diagonal from 0 to 10
>
>>>> x,y = np.meshgrid(np.arange(10.), np.arange(10.))
>>>> x.shape
> (10, 10)
>
>>>> x = x.flatten()
>>>> y = y.flatten()
>>>> z = x**2 + y**2
>>>> z.shape
> (100,)
>>>> from scipy.interpolate import SmoothBivariateSpline
>>>> fcn = SmoothBivariateSpline(x,y,z, s=0, kx=1, ky=1)
>>>> fcn(1, 1)
> array([[ 2.41605245]])
>>>> fcn(1, 5)
> array([[ 26.03716212]])
I don't remember how kx, ky are defined
this actually fits through the points:
>>> fcn = SmoothBivariateSpline(x,y,z, s=0, kx=2, ky=2)
>>> fcn(1, 1)
array([[ 2.]])
>>> fcn(1, 5)
array([[ 26.]])
>>> fcn(2,2)
array([[ 8.]])
Josef
>
> Josef
>
>>
>> Much thanks, and I look forward to feeling stupid!
>> Kevin Gullikson
>>
>>
>> _______________________________________________
>> SciPy-User mailing list
>> SciPy-User@scipy.org
>> http://mail.scipy.org/mailman/listinfo/scipy-user
>>
More information about the SciPy-User
mailing list