本文整理匯總了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)))