当前位置: 首页>>代码示例>>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;未经允许,请勿转载。