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


Python Matrix.zeros方法代码示例

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


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

示例1: test_hstack

# 需要导入模块: from sympy.matrices import Matrix [as 别名]
# 或者: from sympy.matrices.Matrix import zeros [as 别名]
def test_hstack():
    m = ShapingOnlyMatrix(4, 3, lambda i, j: i*3 + j)
    m2 = ShapingOnlyMatrix(3, 4, lambda i, j: i*3 + j)
    assert m == m.hstack(m)
    assert m.hstack(m, m, m) == ShapingOnlyMatrix.hstack(m, m, m) == Matrix([
                [0,  1,  2, 0,  1,  2, 0,  1,  2],
                [3,  4,  5, 3,  4,  5, 3,  4,  5],
                [6,  7,  8, 6,  7,  8, 6,  7,  8],
                [9, 10, 11, 9, 10, 11, 9, 10, 11]])
    raises(ShapeError, lambda: m.hstack(m, m2))
    assert Matrix.hstack() == Matrix()

    # test regression #12938
    M1 = Matrix.zeros(0, 0)
    M2 = Matrix.zeros(0, 1)
    M3 = Matrix.zeros(0, 2)
    M4 = Matrix.zeros(0, 3)
    m = ShapingOnlyMatrix.hstack(M1, M2, M3, M4)
    assert m.rows == 0 and m.cols == 6
开发者ID:asmeurer,项目名称:sympy,代码行数:21,代码来源:test_commonmatrix.py

示例2: zeros

# 需要导入模块: from sympy.matrices import Matrix [as 别名]
# 或者: from sympy.matrices.Matrix import zeros [as 别名]
def zeros(r, c=None, cls=None):
    """Returns a matrix of zeros with ``r`` rows and ``c`` columns;
    if ``c`` is omitted a square matrix will be returned.

    See Also
    ========

    ones
    eye
    diag
    """
    if cls is None:
        from .dense import Matrix as cls
    return cls.zeros(r, c)
开发者ID:gorisaka,项目名称:sympy,代码行数:16,代码来源:dense.py

示例3: test_sparse_matrix

# 需要导入模块: from sympy.matrices import Matrix [as 别名]
# 或者: from sympy.matrices.Matrix import zeros [as 别名]
def test_sparse_matrix():
    def sparse_eye(n):
        return SparseMatrix.eye(n)

    def sparse_zeros(n):
        return SparseMatrix.zeros(n)

    # creation args
    raises(TypeError, lambda: SparseMatrix(1, 2))

    a = SparseMatrix((
        (1, 0),
        (0, 1)
    ))
    assert SparseMatrix(a) == a

    from sympy.matrices import MutableSparseMatrix, MutableDenseMatrix
    a = MutableSparseMatrix([])
    b = MutableDenseMatrix([1, 2])
    assert a.row_join(b) == b
    assert a.col_join(b) == b
    assert type(a.row_join(b)) == type(a)
    assert type(a.col_join(b)) == type(a)

    # make sure 0 x n matrices get stacked correctly
    sparse_matrices = [SparseMatrix.zeros(0, n) for n in range(4)]
    assert SparseMatrix.hstack(*sparse_matrices) == Matrix(0, 6, [])
    sparse_matrices = [SparseMatrix.zeros(n, 0) for n in range(4)]
    assert SparseMatrix.vstack(*sparse_matrices) == Matrix(6, 0, [])

    # test element assignment
    a = SparseMatrix((
        (1, 0),
        (0, 1)
    ))

    a[3] = 4
    assert a[1, 1] == 4
    a[3] = 1

    a[0, 0] = 2
    assert a == SparseMatrix((
        (2, 0),
        (0, 1)
    ))
    a[1, 0] = 5
    assert a == SparseMatrix((
        (2, 0),
        (5, 1)
    ))
    a[1, 1] = 0
    assert a == SparseMatrix((
        (2, 0),
        (5, 0)
    ))
    assert a._smat == {(0, 0): 2, (1, 0): 5}

    # test_multiplication
    a = SparseMatrix((
        (1, 2),
        (3, 1),
        (0, 6),
    ))

    b = SparseMatrix((
        (1, 2),
        (3, 0),
    ))

    c = a*b
    assert c[0, 0] == 7
    assert c[0, 1] == 2
    assert c[1, 0] == 6
    assert c[1, 1] == 6
    assert c[2, 0] == 18
    assert c[2, 1] == 0

    try:
        eval('c = a @ b')
    except SyntaxError:
        pass
    else:
        assert c[0, 0] == 7
        assert c[0, 1] == 2
        assert c[1, 0] == 6
        assert c[1, 1] == 6
        assert c[2, 0] == 18
        assert c[2, 1] == 0

    x = Symbol("x")

    c = b * Symbol("x")
    assert isinstance(c, SparseMatrix)
    assert c[0, 0] == x
    assert c[0, 1] == 2*x
    assert c[1, 0] == 3*x
    assert c[1, 1] == 0

    c = 5 * b
    assert isinstance(c, SparseMatrix)
#.........这里部分代码省略.........
开发者ID:KonstantinTogoi,项目名称:sympy,代码行数:103,代码来源:test_sparse.py

示例4: exp

# 需要导入模块: from sympy.matrices import Matrix [as 别名]
# 或者: from sympy.matrices.Matrix import zeros [as 别名]
#
# Solution given in Cartesian space, but expressed in spectral space
# Remove 2*pi for "2pi-sized" domain
#
U_fromSpec = exp(I*2*pi*(k[0]*x[0]/s[0]+k[1]*x[1]/s[1])) * U_spec


print
print
print("L(U):")
M = getL(U_fromSpec)
pprint(M)

# Remove spectral basis components (This should be possible in general)
Lik = Matrix.zeros(3,3)
Lik[:,0] = simplify(M[:,0]/U_fromSpec[0])
Lik[:,1] = simplify(M[:,1]/U_fromSpec[1])
Lik[:,2] = simplify(M[:,2]/U_fromSpec[2])


if True:
	print
	print
	print("Lik(U):")
	pprint(Lik)


print
print
print("Using omega(k)^2:")
开发者ID:pedrospeixoto,项目名称:sweet,代码行数:32,代码来源:sympy_L_spec_decomposition.py


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