當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。