使用 scipy.optimize 在矩形网格上查找二元样条的根

问题描述

我在二维网格上有数据点,表示某个我不知道其解析形式的函数 g(x,y)。我想做一个样条插值并找到函数具有我称之为“c”的特定值的点。插值函数工作正常,但是当我尝试使用 scipy 的“root”函数时出现错误

from scipy.optimize import RectBivariateSpline,root
import numpy as np
from numpy.random import rand

# do a spline interpolation on rectangular grid
x = np.linspace(0,1)
g = RectBivariateSpline(x,x,rand(x.shape[0],x.shape[0]))

# I want to find the grid points where g = 0.3,so the function is modified accordingly
c = 0.3
g2 = lambda in1,in2 : g(in1,in2) - c

# find the roots with starting values x01 and x02:
x01 = 0.2
x02 = 0.3
# first option:
root(g2,x01,x02)
#second option:
root(g2,[x01,x02])

选项 1 产生错误

ValueError: object too deep for desired array

而选项 2 加注

TypeError: <lambda>() missing 1 required positional argument: 'y'

我需要如何传递起始值?

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)