本文整理汇总了Python中scipy.interpolate.barycentric_interpolate方法的典型用法代码示例。如果您正苦于以下问题:Python interpolate.barycentric_interpolate方法的具体用法?Python interpolate.barycentric_interpolate怎么用?Python interpolate.barycentric_interpolate使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类scipy.interpolate
的用法示例。
在下文中一共展示了interpolate.barycentric_interpolate方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_f
# 需要导入模块: from scipy import interpolate [as 别名]
# 或者: from scipy.interpolate import barycentric_interpolate [as 别名]
def test_f(self):
"""Interpolation of function f with a polynomial p at the equidistant
points x[k] = −1 + 2 * (k / n), k = 0, ..., n."""
n = 20 # n points, so polynomial would be of degree n - 1.
xs = [-1 + 2 * (k / n) for k in range(n)]
ys = [f(x) for x in xs]
for i in range(20):
x0 = uniform(-1.0, 1.0)
y0 = self.algorithm(xs, ys, x0)
bi0 = barycentric_interpolate(xs, ys, x0)
self.assertAlmostEqual(bi0, np.array(y0), 4)
示例2: test_g
# 需要导入模块: from scipy import interpolate [as 别名]
# 或者: from scipy.interpolate import barycentric_interpolate [as 别名]
def test_g(self):
"""Example taken from:
https://en.wikiversity.org/wiki/Numerical_Analysis/Neville%27s_algorithm_examples"""
xs = [16, 64, 100]
ys = [g(x) for x in xs]
x0 = 81
y0 = self.algorithm(xs, ys, x0)
bi0 = barycentric_interpolate(xs, ys, x0)
self.assertAlmostEqual(bi0, np.array(y0), 4)
示例3: _interpolate_scipy_wrapper
# 需要导入模块: from scipy import interpolate [as 别名]
# 或者: from scipy.interpolate import barycentric_interpolate [as 别名]
def _interpolate_scipy_wrapper(x, y, new_x, method, fill_value=None,
bounds_error=False, order=None, **kwargs):
"""
passed off to scipy.interpolate.interp1d. method is scipy's kind.
Returns an array interpolated at new_x. Add any new methods to
the list in _clean_interp_method
"""
try:
from scipy import interpolate
from pandas import DatetimeIndex
except ImportError:
raise ImportError('{0} interpolation requires Scipy'.format(method))
new_x = np.asarray(new_x)
# ignores some kwargs that could be passed along.
alt_methods = {
'barycentric': interpolate.barycentric_interpolate,
'krogh': interpolate.krogh_interpolate,
'piecewise_polynomial': interpolate.piecewise_polynomial_interpolate,
}
if getattr(x, 'is_all_dates', False):
# GH 5975, scipy.interp1d can't hande datetime64s
x, new_x = x.values.astype('i8'), new_x.astype('i8')
try:
alt_methods['pchip'] = interpolate.pchip_interpolate
except AttributeError:
if method == 'pchip':
raise ImportError("Your version of scipy does not support "
"PCHIP interpolation.")
interp1d_methods = ['nearest', 'zero', 'slinear', 'quadratic', 'cubic',
'polynomial']
if method in interp1d_methods:
if method == 'polynomial':
method = order
terp = interpolate.interp1d(x, y, kind=method, fill_value=fill_value,
bounds_error=bounds_error)
new_y = terp(new_x)
elif method == 'spline':
terp = interpolate.UnivariateSpline(x, y, k=order)
new_y = terp(new_x)
else:
method = alt_methods[method]
new_y = method(x, y, new_x)
return new_y