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


Python linalg.cond方法代码示例

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


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

示例1: test_nan

# 需要导入模块: from numpy import linalg [as 别名]
# 或者: from numpy.linalg import cond [as 别名]
def test_nan(self):
        # nans should be passed through, not converted to infs
        ps = [None, 1, -1, 2, -2, 'fro']
        p_pos = [None, 1, 2, 'fro']

        A = np.ones((2, 2))
        A[0,1] = np.nan
        for p in ps:
            c = linalg.cond(A, p)
            assert_(isinstance(c, np.float_))
            assert_(np.isnan(c))

        A = np.ones((3, 2, 2))
        A[1,0,1] = np.nan
        for p in ps:
            c = linalg.cond(A, p)
            assert_(np.isnan(c[1]))
            if p in p_pos:
                assert_(c[0] > 1e15)
                assert_(c[2] > 1e15)
            else:
                assert_(not np.isnan(c[0]))
                assert_(not np.isnan(c[2])) 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:25,代码来源:test_linalg.py

示例2: do

# 需要导入模块: from numpy import linalg [as 别名]
# 或者: from numpy.linalg import cond [as 别名]
def do(self, a, b, tags):
        c = asarray(a)  # a might be a matrix
        if 'size-0' in tags:
            assert_raises(LinAlgError, linalg.cond, c)
            return

        # +-2 norms
        s = linalg.svd(c, compute_uv=False)
        assert_almost_equal(
            linalg.cond(a), s[..., 0] / s[..., -1],
            single_decimal=5, double_decimal=11)
        assert_almost_equal(
            linalg.cond(a, 2), s[..., 0] / s[..., -1],
            single_decimal=5, double_decimal=11)
        assert_almost_equal(
            linalg.cond(a, -2), s[..., -1] / s[..., 0],
            single_decimal=5, double_decimal=11)

        # Other norms
        cinv = np.linalg.inv(c)
        assert_almost_equal(
            linalg.cond(a, 1),
            abs(c).sum(-2).max(-1) * abs(cinv).sum(-2).max(-1),
            single_decimal=5, double_decimal=11)
        assert_almost_equal(
            linalg.cond(a, -1),
            abs(c).sum(-2).min(-1) * abs(cinv).sum(-2).min(-1),
            single_decimal=5, double_decimal=11)
        assert_almost_equal(
            linalg.cond(a, np.inf),
            abs(c).sum(-1).max(-1) * abs(cinv).sum(-1).max(-1),
            single_decimal=5, double_decimal=11)
        assert_almost_equal(
            linalg.cond(a, -np.inf),
            abs(c).sum(-1).min(-1) * abs(cinv).sum(-1).min(-1),
            single_decimal=5, double_decimal=11)
        assert_almost_equal(
            linalg.cond(a, 'fro'),
            np.sqrt((abs(c)**2).sum(-1).sum(-1)
                    * (abs(cinv)**2).sum(-1).sum(-1)),
            single_decimal=5, double_decimal=11) 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:43,代码来源:test_linalg.py

示例3: test_basic_nonsvd

# 需要导入模块: from numpy import linalg [as 别名]
# 或者: from numpy.linalg import cond [as 别名]
def test_basic_nonsvd(self):
        # Smoketest the non-svd norms
        A = array([[1., 0, 1], [0, -2., 0], [0, 0, 3.]])
        assert_almost_equal(linalg.cond(A, inf), 4)
        assert_almost_equal(linalg.cond(A, -inf), 2/3)
        assert_almost_equal(linalg.cond(A, 1), 4)
        assert_almost_equal(linalg.cond(A, -1), 0.5)
        assert_almost_equal(linalg.cond(A, 'fro'), np.sqrt(265 / 12)) 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:10,代码来源:test_linalg.py

示例4: test_singular

# 需要导入模块: from numpy import linalg [as 别名]
# 或者: from numpy.linalg import cond [as 别名]
def test_singular(self):
        # Singular matrices have infinite condition number for
        # positive norms, and negative norms shouldn't raise
        # exceptions
        As = [np.zeros((2, 2)), np.ones((2, 2))]
        p_pos = [None, 1, 2, 'fro']
        p_neg = [-1, -2]
        for A, p in itertools.product(As, p_pos):
            # Inversion may not hit exact infinity, so just check the
            # number is large
            assert_(linalg.cond(A, p) > 1e15)
        for A, p in itertools.product(As, p_neg):
            linalg.cond(A, p) 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:15,代码来源:test_linalg.py

示例5: test_stacked_singular

# 需要导入模块: from numpy import linalg [as 别名]
# 或者: from numpy.linalg import cond [as 别名]
def test_stacked_singular(self):
        # Check behavior when only some of the stacked matrices are
        # singular
        np.random.seed(1234)
        A = np.random.rand(2, 2, 2, 2)
        A[0,0] = 0
        A[1,1] = 0

        for p in (None, 1, 2, 'fro', -1, -2):
            c = linalg.cond(A, p)
            assert_equal(c[0,0], np.inf)
            assert_equal(c[1,1], np.inf)
            assert_(np.isfinite(c[0,1]))
            assert_(np.isfinite(c[1,0])) 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:16,代码来源:test_linalg.py

示例6: do

# 需要导入模块: from numpy import linalg [as 别名]
# 或者: from numpy.linalg import cond [as 别名]
def do(self, a, b):
        c = asarray(a)  # a might be a matrix
        s = linalg.svd(c, compute_uv=False)
        old_assert_almost_equal(
            s[..., 0] / s[..., -1], linalg.cond(a), decimal=5) 
开发者ID:ryfeus,项目名称:lambda-packs,代码行数:7,代码来源:test_linalg.py

示例7: test_stacked_arrays_explicitly

# 需要导入模块: from numpy import linalg [as 别名]
# 或者: from numpy.linalg import cond [as 别名]
def test_stacked_arrays_explicitly(self):
        A = np.array([[1., 2., 1.], [0, -2., 0], [6., 2., 3.]])
        assert_equal(linalg.cond(A), linalg.cond(A[None, ...])[0]) 
开发者ID:ryfeus,项目名称:lambda-packs,代码行数:5,代码来源:test_linalg.py

示例8: test

# 需要导入模块: from numpy import linalg [as 别名]
# 或者: from numpy.linalg import cond [as 别名]
def test(self):
        A = array([[1., 0, 0], [0, -2., 0], [0, 0, 3.]])
        assert_almost_equal(linalg.cond(A, inf), 3.) 
开发者ID:ryfeus,项目名称:lambda-packs,代码行数:5,代码来源:test_linalg.py

示例9: do

# 需要导入模块: from numpy import linalg [as 别名]
# 或者: from numpy.linalg import cond [as 别名]
def do(self, a, b, tags):
        c = asarray(a)  # a might be a matrix
        if 'size-0' in tags:
            assert_raises(LinAlgError, linalg.svd, c, compute_uv=False)
            return
        s = linalg.svd(c, compute_uv=False)
        assert_almost_equal(
            s[..., 0] / s[..., -1], linalg.cond(a),
            single_decimal=5, double_decimal=11) 
开发者ID:birforce,项目名称:vnpy_crypto,代码行数:11,代码来源:test_linalg.py

示例10: do

# 需要导入模块: from numpy import linalg [as 别名]
# 或者: from numpy.linalg import cond [as 别名]
def do(self, a, b):
        c = asarray(a) # a might be a matrix
        s = linalg.svd(c, compute_uv=False)
        old_assert_almost_equal(s[0]/s[-1], linalg.cond(a), decimal=5) 
开发者ID:ktraunmueller,项目名称:Computable,代码行数:6,代码来源:test_linalg.py


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