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


Python PPoly.roots方法代码示例

本文整理汇总了Python中scipy.interpolate.PPoly.roots方法的典型用法代码示例。如果您正苦于以下问题:Python PPoly.roots方法的具体用法?Python PPoly.roots怎么用?Python PPoly.roots使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在scipy.interpolate.PPoly的用法示例。


在下文中一共展示了PPoly.roots方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_roots_discont

# 需要导入模块: from scipy.interpolate import PPoly [as 别名]
# 或者: from scipy.interpolate.PPoly import roots [as 别名]
 def test_roots_discont(self):
     # Check that a discontinuity across zero is reported as root
     c = np.array([[1], [-1]]).T
     x = np.array([0, 0.5, 1])
     pp = PPoly(c, x)
     assert_array_equal(pp.roots(), [0.5])
     assert_array_equal(pp.roots(discontinuity=False), [])
开发者ID:AGPeddle,项目名称:scipy,代码行数:9,代码来源:test_interpolate.py

示例2: test_roots_repeated

# 需要导入模块: from scipy.interpolate import PPoly [as 别名]
# 或者: from scipy.interpolate.PPoly import roots [as 别名]
    def test_roots_repeated(self):
        # Check roots repeated in multiple sections are reported only
        # once.

        # [(x + 1)**2 - 1, -x**2] ; x == 0 is a repeated root
        c = np.array([[1, 0, -1], [-1, 0, 0]]).T
        x = np.array([-1, 0, 1])

        pp = PPoly(c, x)
        assert_array_equal(pp.roots(), [-2, 0])
        assert_array_equal(pp.roots(extrapolate=False), [0])
开发者ID:AGPeddle,项目名称:scipy,代码行数:13,代码来源:test_interpolate.py

示例3: test_roots_random

# 需要导入模块: from scipy.interpolate import PPoly [as 别名]
# 或者: from scipy.interpolate.PPoly import roots [as 别名]
    def test_roots_random(self):
        # Check high-order polynomials with random coefficients
        np.random.seed(1234)

        num = 0

        for extrapolate in (True, False):
            for order in range(0, 20):
                x = np.unique(np.r_[0, 10 * np.random.rand(30), 10])
                c = 2*np.random.rand(order+1, len(x)-1, 2, 3) - 1

                pp = PPoly(c, x)
                r = pp.roots(discontinuity=False, extrapolate=extrapolate)

                for i in range(2):
                    for j in range(3):
                        rr = r[i,j]
                        if rr.size > 0:
                            # Check that the reported roots indeed are roots
                            num += rr.size
                            val = pp(rr, extrapolate=extrapolate)[:,i,j]
                            cmpval = pp(rr, nu=1, extrapolate=extrapolate)[:,i,j]
                            assert_allclose(val/cmpval, 0, atol=1e-7,
                                            err_msg="(%r) r = %s" % (extrapolate,
                                                                     repr(rr),))

        # Check that we checked a number of roots
        assert_(num > 100, repr(num))
开发者ID:AGPeddle,项目名称:scipy,代码行数:30,代码来源:test_interpolate.py

示例4: test_roots_idzero

# 需要导入模块: from scipy.interpolate import PPoly [as 别名]
# 或者: from scipy.interpolate.PPoly import roots [as 别名]
    def test_roots_idzero(self):
        # Roots for piecewise polynomials with identically zero
        # sections.
        c = np.array([[-1, 0.25], [0, 0], [-1, 0.25]]).T
        x = np.array([0, 0.4, 0.6, 1.0])

        pp = PPoly(c, x)
        assert_array_equal(pp.roots(),
                           [0.25, 0.4, np.nan, 0.6 + 0.25])
开发者ID:AGPeddle,项目名称:scipy,代码行数:11,代码来源:test_interpolate.py

示例5: test_extrapolate_attr

# 需要导入模块: from scipy.interpolate import PPoly [as 别名]
# 或者: from scipy.interpolate.PPoly import roots [as 别名]
    def test_extrapolate_attr(self):
        # [ 1 - x**2 ]
        c = np.array([[-1, 0, 1]]).T
        x = np.array([0, 1])

        for extrapolate in [True, False, None]:
            pp = PPoly(c, x, extrapolate=extrapolate)
            pp_d = pp.derivative()
            pp_i = pp.antiderivative()

            if extrapolate is False:
                assert_(np.isnan(pp([-0.1, 1.1])).all())
                assert_(np.isnan(pp_i([-0.1, 1.1])).all())
                assert_(np.isnan(pp_d([-0.1, 1.1])).all())
                assert_equal(pp.roots(), [1])
            else:
                assert_allclose(pp([-0.1, 1.1]), [1-0.1**2, 1-1.1**2])
                assert_(not np.isnan(pp_i([-0.1, 1.1])).any())
                assert_(not np.isnan(pp_d([-0.1, 1.1])).any())
                assert_allclose(pp.roots(), [1, -1])
开发者ID:AGPeddle,项目名称:scipy,代码行数:22,代码来源:test_interpolate.py


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