当前位置: 首页>>代码示例>>Python>>正文


Python BSpline.basis_element方法代码示例

本文整理汇总了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)
开发者ID:Brucechen13,项目名称:scipy,代码行数:14,代码来源:test_bsplines.py

示例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
开发者ID:Brucechen13,项目名称:scipy,代码行数:11,代码来源:test_bsplines.py

示例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)
开发者ID:alchemyst,项目名称:scipy,代码行数:11,代码来源:test_bsplines.py

示例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)
开发者ID:Brucechen13,项目名称:scipy,代码行数:39,代码来源:test_bsplines.py

示例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)))
开发者ID:Brucechen13,项目名称:scipy,代码行数:6,代码来源:test_bsplines.py


注:本文中的scipy.interpolate.BSpline.basis_element方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。