當前位置: 首頁>>代碼示例>>Python>>正文


Python numpy.bmat方法代碼示例

本文整理匯總了Python中numpy.bmat方法的典型用法代碼示例。如果您正苦於以下問題:Python numpy.bmat方法的具體用法?Python numpy.bmat怎麽用?Python numpy.bmat使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在numpy的用法示例。


在下文中一共展示了numpy.bmat方法的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: diagonalize

# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import bmat [as 別名]
def diagonalize(a, b, nroots=4):
    a_aa, a_ab, a_bb = a
    b_aa, b_ab, b_bb = b
    nocc_a, nvir_a, nocc_b, nvir_b = a_ab.shape
    a_aa = a_aa.reshape((nocc_a*nvir_a,nocc_a*nvir_a))
    a_ab = a_ab.reshape((nocc_a*nvir_a,nocc_b*nvir_b))
    a_bb = a_bb.reshape((nocc_b*nvir_b,nocc_b*nvir_b))
    b_aa = b_aa.reshape((nocc_a*nvir_a,nocc_a*nvir_a))
    b_ab = b_ab.reshape((nocc_a*nvir_a,nocc_b*nvir_b))
    b_bb = b_bb.reshape((nocc_b*nvir_b,nocc_b*nvir_b))
    a = numpy.bmat([[ a_aa  , a_ab],
                    [ a_ab.T, a_bb]])
    b = numpy.bmat([[ b_aa  , b_ab],
                    [ b_ab.T, b_bb]])
    e = numpy.linalg.eig(numpy.bmat([[a        , b       ],
                                     [-b.conj(),-a.conj()]]))[0]
    lowest_e = numpy.sort(e[e.real > 0].real)[:nroots]
    return lowest_e 
開發者ID:pyscf,項目名稱:pyscf,代碼行數:20,代碼來源:21-matrix_A_B.py

示例2: diagonalize

# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import bmat [as 別名]
def diagonalize(a, b, nroots=4):
    a_aa, a_ab, a_bb = a
    b_aa, b_ab, b_bb = b
    nocc_a, nvir_a, nocc_b, nvir_b = a_ab.shape
    a_aa = a_aa.reshape((nocc_a*nvir_a,nocc_a*nvir_a))
    a_ab = a_ab.reshape((nocc_a*nvir_a,nocc_b*nvir_b))
    a_bb = a_bb.reshape((nocc_b*nvir_b,nocc_b*nvir_b))
    b_aa = b_aa.reshape((nocc_a*nvir_a,nocc_a*nvir_a))
    b_ab = b_ab.reshape((nocc_a*nvir_a,nocc_b*nvir_b))
    b_bb = b_bb.reshape((nocc_b*nvir_b,nocc_b*nvir_b))
    a = numpy.bmat([[ a_aa  , a_ab],
                    [ a_ab.T, a_bb]])
    b = numpy.bmat([[ b_aa  , b_ab],
                    [ b_ab.T, b_bb]])
    e = numpy.linalg.eig(numpy.bmat([[a        , b       ],
                                     [-b.conj(),-a.conj()]]))[0]
    lowest_e = numpy.sort(e[e.real > 0].real)[:nroots]
    lowest_e = lowest_e[lowest_e > 1e-3]
    return lowest_e 
開發者ID:pyscf,項目名稱:pyscf,代碼行數:21,代碼來源:test_tduks.py

示例3: test_basic

# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import bmat [as 別名]
def test_basic(self):
        A = np.array([[1, 2], [3, 4]])
        mA = matrix(A)
        assert_(np.all(mA.A == A))

        B = bmat("A,A;A,A")
        C = bmat([[A, A], [A, A]])
        D = np.array([[1, 2, 1, 2],
                      [3, 4, 3, 4],
                      [1, 2, 1, 2],
                      [3, 4, 3, 4]])
        assert_(np.all(B.A == D))
        assert_(np.all(C.A == D))

        E = np.array([[5, 6], [7, 8]])
        AEresult = matrix([[1, 2, 5, 6], [3, 4, 7, 8]])
        assert_(np.all(bmat([A, E]) == AEresult))

        vec = np.arange(5)
        mvec = matrix(vec)
        assert_(mvec.shape == (1, 5)) 
開發者ID:Frank-qlu,項目名稱:recruit,代碼行數:23,代碼來源:test_defmatrix.py

示例4: test_bmat_nondefault_str

# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import bmat [as 別名]
def test_bmat_nondefault_str(self):
        A = np.array([[1, 2], [3, 4]])
        B = np.array([[5, 6], [7, 8]])
        Aresult = np.array([[1, 2, 1, 2],
                            [3, 4, 3, 4],
                            [1, 2, 1, 2],
                            [3, 4, 3, 4]])
        mixresult = np.array([[1, 2, 5, 6],
                              [3, 4, 7, 8],
                              [5, 6, 1, 2],
                              [7, 8, 3, 4]])
        assert_(np.all(bmat("A,A;A,A") == Aresult))
        assert_(np.all(bmat("A,A;A,A", ldict={'A':B}) == Aresult))
        assert_raises(TypeError, bmat, "A,A;A,A", gdict={'A':B})
        assert_(
            np.all(bmat("A,A;A,A", ldict={'A':A}, gdict={'A':B}) == Aresult))
        b2 = bmat("A,B;C,D", ldict={'A':A,'B':B}, gdict={'C':B,'D':A})
        assert_(np.all(b2 == mixresult)) 
開發者ID:Frank-qlu,項目名稱:recruit,代碼行數:20,代碼來源:test_defmatrix.py

示例5: test_np

# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import bmat [as 別名]
def test_np():
    npr.seed(0)

    nx, nineq, neq = 4, 6, 7
    Q = npr.randn(nx, nx)
    G = npr.randn(nineq, nx)
    A = npr.randn(neq, nx)
    D = np.diag(npr.rand(nineq))

    K_ = np.bmat((
        (Q, np.zeros((nx, nineq)), G.T, A.T),
        (np.zeros((nineq, nx)), D, np.eye(nineq), np.zeros((nineq, neq))),
        (G, np.eye(nineq), np.zeros((nineq, nineq + neq))),
        (A, np.zeros((neq, nineq + nineq + neq)))
    ))

    K = block((
        (Q,   0, G.T, A.T),
        (0,   D, 'I',   0),
        (G, 'I',   0,   0),
        (A,   0,   0,   0)
    ))

    assert np.allclose(K_, K) 
開發者ID:bamos,項目名稱:block,代碼行數:26,代碼來源:test.py

示例6: cov_params_default

# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import bmat [as 別名]
def cov_params_default(self):  # p.296 (7.2.21)
        # Sigma_co described on p. 287
        beta = self.beta
        if self.det_coef_coint.size > 0:
            beta = vstack((beta, self.det_coef_coint))
        dt = self.deterministic
        num_det = ("co" in dt) + ("lo" in dt)
        num_det += (self.seasons-1) if self.seasons else 0
        if self.exog is not None:
            num_det += self.exog.shape[1]
        b_id = scipy.linalg.block_diag(beta,
                                       np.identity(self.neqs * (self.k_ar-1) +
                                                   num_det))

        y_lag1 = self._y_lag1
        b_y = beta.T.dot(y_lag1)
        omega11 = b_y.dot(b_y.T)
        omega12 = b_y.dot(self._delta_x.T)
        omega21 = omega12.T
        omega22 = self._delta_x.dot(self._delta_x.T)
        omega = np.bmat([[omega11, omega12],
                         [omega21, omega22]]).A

        mat1 = b_id.dot(inv(omega)).dot(b_id.T)
        return np.kron(mat1, self.sigma_u) 
開發者ID:birforce,項目名稱:vnpy_crypto,代碼行數:27,代碼來源:vecm.py

示例7: test_basic

# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import bmat [as 別名]
def test_basic(self):
        A = array([[1, 2], [3, 4]])
        mA = matrix(A)
        assert_(all(mA.A == A))

        B = bmat("A,A;A,A")
        C = bmat([[A, A], [A, A]])
        D = array([[1, 2, 1, 2],
                   [3, 4, 3, 4],
                   [1, 2, 1, 2],
                   [3, 4, 3, 4]])
        assert_(all(B.A == D))
        assert_(all(C.A == D))

        E = array([[5, 6], [7, 8]])
        AEresult = matrix([[1, 2, 5, 6], [3, 4, 7, 8]])
        assert_(all(bmat([A, E]) == AEresult))

        vec = arange(5)
        mvec = matrix(vec)
        assert_(mvec.shape == (1, 5)) 
開發者ID:ktraunmueller,項目名稱:Computable,代碼行數:23,代碼來源:test_defmatrix.py

示例8: test_bmat_nondefault_str

# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import bmat [as 別名]
def test_bmat_nondefault_str(self):
        A = array([[1, 2], [3, 4]])
        B = array([[5, 6], [7, 8]])
        Aresult = array([[1, 2, 1, 2],
                         [3, 4, 3, 4],
                         [1, 2, 1, 2],
                         [3, 4, 3, 4]])
        Bresult = array([[5, 6, 5, 6],
                         [7, 8, 7, 8],
                         [5, 6, 5, 6],
                         [7, 8, 7, 8]])
        mixresult = array([[1, 2, 5, 6],
                           [3, 4, 7, 8],
                           [5, 6, 1, 2],
                           [7, 8, 3, 4]])
        assert_(all(bmat("A,A;A,A") == Aresult))
        assert_(all(bmat("A,A;A,A", ldict={'A':B}) == Aresult))
        assert_raises(TypeError, bmat, "A,A;A,A", gdict={'A':B})
        assert_(all(bmat("A,A;A,A", ldict={'A':A}, gdict={'A':B}) == Aresult))
        b2 = bmat("A,B;C,D", ldict={'A':A,'B':B}, gdict={'C':B,'D':A})
        assert_(all(b2 == mixresult)) 
開發者ID:ktraunmueller,項目名稱:Computable,代碼行數:23,代碼來源:test_defmatrix.py

示例9: circumcenter

# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import bmat [as 別名]
def circumcenter(self, tri):
        """Compute circumcenter and circumradius of a triangle in 2D.
        Uses an extension of the method described here:
        http://www.ics.uci.edu/~eppstein/junkyard/circumcenter.html
        """
        pts = np.asarray([self.coords[v] for v in tri])
        pts2 = np.dot(pts, pts.T)
        A = np.bmat([[2 * pts2, [[1],
                                 [1],
                                 [1]]],
                      [[[1, 1, 1, 0]]]])

        b = np.hstack((np.sum(pts * pts, axis=1), [1]))
        x = np.linalg.solve(A, b)
        bary_coords = x[:-1]
        center = np.dot(bary_coords, pts)

        # radius = np.linalg.norm(pts[0] - center) # euclidean distance
        radius = np.sum(np.square(pts[0] - center))  # squared distance
        return (center, radius) 
開發者ID:jmespadero,項目名稱:pyDelaunay2D,代碼行數:22,代碼來源:delaunay2D.py

示例10: Circumcenter

# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import bmat [as 別名]
def Circumcenter(self, tri):
        """Compute Circumcenter and circumradius of a triangle in 2D.
        Uses an extension of the method described here:
        http://www.ics.uci.edu/~eppstein/junkyard/circumcenter.html
        """
        pts = np.asarray([self.coords[v] for v in tri])
        pts2 = np.dot(pts, pts.T)
        A = np.bmat([[2 * pts2, [[1],
                                 [1],
                                 [1]]],
                      [[[1, 1, 1, 0]]]])

        b = np.hstack((np.sum(pts * pts, axis=1), [1]))
        x = np.linalg.solve(A, b)
        bary_coords = x[:-1]
        center = np.dot(bary_coords, pts)

        # radius = np.linalg.norm(pts[0] - center) # euclidean distance
        radius = np.sum(np.square(pts[0] - center))  # squared distance
        return (center, radius) 
開發者ID:gasongjian,項目名稱:reportgen,代碼行數:22,代碼來源:delaunay.py


注:本文中的numpy.bmat方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。