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


Python symengine_wrapper.DenseMatrix类代码示例

本文整理汇总了Python中symengine.lib.symengine_wrapper.DenseMatrix的典型用法代码示例。如果您正苦于以下问题:Python DenseMatrix类的具体用法?Python DenseMatrix怎么用?Python DenseMatrix使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: test_submatrix

def test_submatrix():
    A = DenseMatrix(3, 3, [1, 2, 3, 4, 5, 6, 7, 8, 9])

    assert A.submatrix(0, 0, 0, 2) == DenseMatrix(1, 3, [1, 2, 3])
    assert A.submatrix(2, 2, 0, 2) == DenseMatrix(1, 3, [7, 8, 9])
    assert A.submatrix(0, 1, 1, 2) == DenseMatrix(2, 2, [2, 3, 5, 6])
    assert A.submatrix(1, 2, 0, 2) == DenseMatrix(2, 3, [4, 5, 6, 7, 8, 9])
开发者ID:v0dro,项目名称:symengine,代码行数:7,代码来源:test_matrices.py

示例2: test_transpose

def test_transpose():
    A = DenseMatrix(3, 3, [1, 2, 3, 4, 5, 6, 7, 8, 9])

    assert A.transpose() == DenseMatrix(3, 3, [1, 4, 7, 2, 5, 8, 3, 6, 9])

    A = DenseMatrix(2, 2, [1, 2, 2, 1])

    assert A.transpose() == A
开发者ID:lk11235,项目名称:symengine.py,代码行数:8,代码来源:test_matrices.py

示例3: test_DenseMatrix_symbols

def test_DenseMatrix_symbols():
    x, y, z = symbols("x y z")
    D = DenseMatrix(4, 4,
            [1, 0, 1, 0,
            0, z, y, 0,
            z, 1, x, 1,
            1, 1, 0, 0])
    assert D.get(1, 2) == y
开发者ID:lk11235,项目名称:symengine.py,代码行数:8,代码来源:test_matrices.py

示例4: test_dump_real

def test_dump_real():
    if not HAVE_NUMPY:  # nosetests work-around
        return
    ref = [1, 2, 3, 4]
    A = DenseMatrix(2, 2, ref)
    out = np.empty(4)
    A.dump_real(out)
    assert np.allclose(out, ref)
开发者ID:lk11235,项目名称:symengine.py,代码行数:8,代码来源:test_matrices.py

示例5: test_add_scalar

def test_add_scalar():
    A = DenseMatrix(2, 2, [1, 2, 3, 4])

    a = Symbol("a")
    assert A.add_scalar(a) == DenseMatrix(2, 2, [1 + a, 2 + a, 3 + a, 4 + a])

    i5 = Integer(5)
    assert A.add_scalar(i5) == DenseMatrix(2, 2, [6, 7, 8, 9])
开发者ID:v0dro,项目名称:symengine,代码行数:8,代码来源:test_matrices.py

示例6: test_dump_complex

def test_dump_complex():
    if not HAVE_NUMPY:  # nosetests work-around
        return
    ref = [1j, 2j, 3j, 4j]
    A = DenseMatrix(2, 2, ref)
    out = np.empty(4, dtype=np.complex128)
    A.dump_complex(out)
    assert np.allclose(out, ref)
开发者ID:lk11235,项目名称:symengine.py,代码行数:8,代码来源:test_matrices.py

示例7: test_mul_scalar

def test_mul_scalar():
    A = DenseMatrix(2, 2, [1, 2, 3, 4])

    a = Symbol("a")
    assert A.mul_scalar(a) == DenseMatrix(2, 2, [a, 2*a, 3*a, 4*a])

    i5 = Integer(5)
    assert A.mul_scalar(i5) == DenseMatrix(2, 2, [5, 10, 15, 20])
开发者ID:v0dro,项目名称:symengine,代码行数:8,代码来源:test_matrices.py

示例8: test_jacobian

def test_jacobian():
    x, y, z, t = symbols("x y z t")
    J_correct = DenseMatrix(4, 4,
            [1, 0, 1, 0,
            0, z, y, 0,
            z, 1, x, 1,
            1, 1, 0, 0])
    D = DenseMatrix(4, 1, [x+z, y*z, z*x+y+t, x+y])
    x = DenseMatrix(4, 1, [x, y, z, t])
    J = D.jacobian(x)
    assert J == J_correct
开发者ID:lk11235,项目名称:symengine.py,代码行数:11,代码来源:test_matrices.py

示例9: test_add_scalar

def test_add_scalar():
    A = DenseMatrix(2, 2, [1, 2, 3, 4])

    a = Symbol("a")
    assert A.add_scalar(a) == DenseMatrix(2, 2, [1 + a, 2 + a, 3 + a, 4 + a])

    i5 = Integer(5)
    assert A.add_scalar(i5) == DenseMatrix(2, 2, [6, 7, 8, 9])
    
    raises(TypeError, lambda: A + 5)
    raises(TypeError, lambda: 5 + A)
开发者ID:parsoyaarihant,项目名称:symengine.py,代码行数:11,代码来源:test_matrices.py

示例10: test_solve

def test_solve():
    A = DenseMatrix(4, 4, [1, 2, 3, 4, 2, 2, 3, 4, 3, 3, 3, 4, 9, 8, 7, 6])
    b = DenseMatrix(4, 1, [10, 11, 13, 30])
    y = DenseMatrix(4, 1, [1, 1, 1, 1]);

    x = A.solve(b, 'LU')
    assert x == y
    x = A.solve(b, 'FFLU')
    assert x == y
    x = A.solve(b, 'FFGJ')
    assert x == y
开发者ID:lk11235,项目名称:symengine.py,代码行数:11,代码来源:test_matrices.py

示例11: test_add_matrix

def test_add_matrix():
    A = DenseMatrix(2, 2, [1, 2, 3, 4])
    B = DenseMatrix(2, 2, [1, 0, 0, 1])

    assert A.add_matrix(B) == DenseMatrix(2, 2, [2, 2, 3, 5])

    a = Symbol("a")
    b = Symbol("b")
    c = Symbol("c")
    d = Symbol("d")
    A = DenseMatrix(2, 2, [a + b, a - b, a, b])
    B = DenseMatrix(2, 2, [a - b, a + b, -a, b])

    assert A.add_matrix(B) == DenseMatrix(2, 2, [2*a, 2*a, 0, 2*b])
开发者ID:v0dro,项目名称:symengine,代码行数:14,代码来源:test_matrices.py

示例12: test_mul_matrix

def test_mul_matrix():
    A = DenseMatrix(2, 2, [1, 2, 3, 4])
    B = DenseMatrix(2, 2, [1, 0, 0, 1])

    assert A.mul_matrix(B) == A

    a = Symbol("a")
    b = Symbol("b")
    c = Symbol("c")
    d = Symbol("d")
    A = DenseMatrix(2, 2, [a, b, c, d])
    B = DenseMatrix(2, 2, [1, 0, 1, 0])

    assert A.mul_matrix(B) == DenseMatrix(2, 2, [a + b, 0, c + d, 0])
开发者ID:cbehan,项目名称:symengine,代码行数:14,代码来源:test_matrices.py

示例13: test_add_matrix

def test_add_matrix():
    A = DenseMatrix(2, 2, [1, 2, 3, 4])
    B = DenseMatrix(2, 2, [1, 0, 0, 1])

    assert A.add_matrix(B) == DenseMatrix(2, 2, [2, 2, 3, 5])

    a = Symbol("a")
    b = Symbol("b")
    c = Symbol("c")
    d = Symbol("d")
    A = DenseMatrix(2, 2, [a + b, a - b, a, b])
    B = DenseMatrix(2, 2, [a - b, a + b, -a, b])

    assert A.add_matrix(B) == DenseMatrix(2, 2, [2*a, 2*a, 0, 2*b])
    assert A + B == DenseMatrix(2, 2, [2*a, 2*a, 0, 2*b])

    C = DenseMatrix(1, 2, [a, b])
    raises(ShapeError, lambda: A + C)
开发者ID:lk11235,项目名称:symengine.py,代码行数:18,代码来源:test_matrices.py

示例14: test_get

def test_get():
    A = DenseMatrix([[1, 2], [3, 4]])

    assert A.get(0, 0) == 1
    assert A.get(0, 1) == 2
    assert A.get(1, 1) == 4

    a = Symbol("a")
    b = Symbol("b")
    c = Symbol("c")
    d = Symbol("d")
    A = DenseMatrix(2, 2, [a, b, c, d])

    assert A.get(0, 0) == a
    assert A.get(1, 0) == c
    assert A.get(1, 1) == d

    assert A.get(-1, 0) == c
    assert A.get(-1, -1) == d

    raises(IndexError, lambda: A.get(2, 0))
    raises(IndexError, lambda: A.get(0, 2))
    raises(IndexError, lambda: A.get(-3, 0))
开发者ID:lk11235,项目名称:symengine.py,代码行数:23,代码来源:test_matrices.py

示例15: test_inv

def test_inv():
    A = DenseMatrix(2, 2, [1, 0, 0, 1])
    assert A.inv() == A

    A = DenseMatrix(2, 2, [1, 2, 2, 3])
    B = DenseMatrix(2, 2, [-3, 2, 2, -1])

    assert A.inv('LU') == B
    assert A.inv('FFLU') == B
    assert A.inv('GJ') == B
开发者ID:lk11235,项目名称:symengine.py,代码行数:10,代码来源:test_matrices.py


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