本文整理汇总了Python中scipy.interpolate.BSpline.basis_element方法的典型用法代码示例。如果您正苦于以下问题:Python BSpline.basis_element方法的具体用法?Python BSpline.basis_element怎么用?Python BSpline.basis_element使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类scipy.interpolate.BSpline
的用法示例。
在下文中一共展示了BSpline.basis_element方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_basis_element_quadratic
# 需要导入模块: from scipy.interpolate import BSpline [as 别名]
# 或者: from scipy.interpolate.BSpline import basis_element [as 别名]
def test_basis_element_quadratic(self):
xx = np.linspace(-1, 4, 20)
b = BSpline.basis_element(t=[0, 1, 2, 3])
assert_allclose(b(xx),
splev(xx, (b.t, b.c, b.k)), atol=1e-14)
assert_allclose(b(xx),
B_0123(xx), atol=1e-14)
b = BSpline.basis_element(t=[0, 1, 1, 2])
xx = np.linspace(0, 2, 10)
assert_allclose(b(xx),
np.where(xx < 1, xx*xx, (2.-xx)**2), atol=1e-14)
示例2: _sum_basis_elements
# 需要导入模块: from scipy.interpolate import BSpline [as 别名]
# 或者: from scipy.interpolate.BSpline import basis_element [as 别名]
def _sum_basis_elements(x, t, c, k):
n = len(t) - (k+1)
assert n >= k+1
assert len(c) >= n
s = 0.
for i in range(n):
b = BSpline.basis_element(t[i:i+k+2], extrapolate=False)(x)
s += c[i] * np.nan_to_num(b) # zero out out-of-bounds elements
return s
示例3: test_integral
# 需要导入模块: from scipy.interpolate import BSpline [as 别名]
# 或者: from scipy.interpolate.BSpline import basis_element [as 别名]
def test_integral(self):
b = BSpline.basis_element([0, 1, 2]) # x for x < 1 else 2 - x
assert_allclose(b.integrate(0, 1), 0.5)
assert_allclose(b.integrate(1, 0), -0.5)
# extrapolate or zeros outside of [0, 2]; default is yes
assert_allclose(b.integrate(-1, 1), 0)
assert_allclose(b.integrate(-1, 1, extrapolate=True), 0)
assert_allclose(b.integrate(-1, 1, extrapolate=False), 0.5)
示例4: test_integral
# 需要导入模块: from scipy.interpolate import BSpline [as 别名]
# 或者: from scipy.interpolate.BSpline import basis_element [as 别名]
def test_integral(self):
b = BSpline.basis_element([0, 1, 2]) # x for x < 1 else 2 - x
assert_allclose(b.integrate(0, 1), 0.5)
assert_allclose(b.integrate(1, 0), -1 * 0.5)
assert_allclose(b.integrate(1, 0), -0.5)
# extrapolate or zeros outside of [0, 2]; default is yes
assert_allclose(b.integrate(-1, 1), 0)
assert_allclose(b.integrate(-1, 1, extrapolate=True), 0)
assert_allclose(b.integrate(-1, 1, extrapolate=False), 0.5)
assert_allclose(b.integrate(1, -1, extrapolate=False), -1 * 0.5)
# Test ``_fitpack._splint()``
t, c, k = b.tck
assert_allclose(b.integrate(1, -1, extrapolate=False),
_splint(t, c, k, 1, -1)[0])
# Test ``extrapolate='periodic'``.
b.extrapolate = 'periodic'
i = b.antiderivative()
period_int = i(2) - i(0)
assert_allclose(b.integrate(0, 2), period_int)
assert_allclose(b.integrate(2, 0), -1 * period_int)
assert_allclose(b.integrate(-9, -7), period_int)
assert_allclose(b.integrate(-8, -4), 2 * period_int)
assert_allclose(b.integrate(0.5, 1.5), i(1.5) - i(0.5))
assert_allclose(b.integrate(1.5, 3), i(1) - i(0) + i(2) - i(1.5))
assert_allclose(b.integrate(1.5 + 12, 3 + 12),
i(1) - i(0) + i(2) - i(1.5))
assert_allclose(b.integrate(1.5, 3 + 12),
i(1) - i(0) + i(2) - i(1.5) + 6 * period_int)
assert_allclose(b.integrate(0, -1), i(0) - i(1))
assert_allclose(b.integrate(-9, -10), i(0) - i(1))
assert_allclose(b.integrate(0, -9), i(1) - i(2) - 4 * period_int)
示例5: test_nan
# 需要导入模块: from scipy.interpolate import BSpline [as 别名]
# 或者: from scipy.interpolate.BSpline import basis_element [as 别名]
def test_nan(self):
# nan in, nan out.
b = BSpline.basis_element([0, 1, 1, 2])
assert_(np.isnan(b(np.nan)))