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


Python immutable.ImmutableMatrix类代码示例

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


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

示例1: as_immutable

 def as_immutable(self):
     """Returns an Immutable version of this Matrix
     """
     from immutable import ImmutableMatrix as cls
     if self.rows:
         return cls._new(self.tolist())
     return cls._new(0, self.cols, [])
开发者ID:FireJade,项目名称:sympy,代码行数:7,代码来源:dense.py

示例2: diag

def diag(*values, **kwargs):
    """Create a sparse, diagonal matrix from a list of diagonal values.

    Notes
    =====

    When arguments are matrices they are fitted in resultant matrix.

    The returned matrix is a mutable, dense matrix. To make it a different
    type, send the desired class for keyword ``cls``.

    Examples
    ========

    >>> from sympy.matrices import diag, Matrix, ones
    >>> diag(1, 2, 3)
    [1, 0, 0]
    [0, 2, 0]
    [0, 0, 3]
    >>> diag(*[1, 2, 3])
    [1, 0, 0]
    [0, 2, 0]
    [0, 0, 3]

    The diagonal elements can be matrices; diagonal filling will
    continue on the diagonal from the last element of the matrix:

    >>> from sympy.abc import x, y, z
    >>> a = Matrix([x, y, z])
    >>> b = Matrix([[1, 2], [3, 4]])
    >>> c = Matrix([[5, 6]])
    >>> diag(a, 7, b, c)
    [x, 0, 0, 0, 0, 0]
    [y, 0, 0, 0, 0, 0]
    [z, 0, 0, 0, 0, 0]
    [0, 7, 0, 0, 0, 0]
    [0, 0, 1, 2, 0, 0]
    [0, 0, 3, 4, 0, 0]
    [0, 0, 0, 0, 5, 6]

    When diagonal elements are lists, they will be treated as arguments
    to Matrix:

    >>> diag([1, 2, 3], 4)
    [1, 0]
    [2, 0]
    [3, 0]
    [0, 4]
    >>> diag([[1, 2, 3]], 4)
    [1, 2, 3, 0]
    [0, 0, 0, 4]

    A given band off the diagonal can be made by padding with a
    vertical or horizontal "kerning" vector:

    >>> hpad = ones(0, 2)
    >>> vpad = ones(2, 0)
    >>> diag(vpad, 1, 2, 3, hpad) + diag(hpad, 4, 5, 6, vpad)
    [0, 0, 4, 0, 0]
    [0, 0, 0, 5, 0]
    [1, 0, 0, 0, 6]
    [0, 2, 0, 0, 0]
    [0, 0, 3, 0, 0]


    The type is mutable by default but can be made immutable by setting
    the ``mutable`` flag to False:

    >>> type(diag(1))
    <class 'sympy.matrices.dense.MutableDenseMatrix'>
    >>> from sympy.matrices import ImmutableMatrix
    >>> type(diag(1, cls=ImmutableMatrix))
    <class 'sympy.matrices.immutable.ImmutableMatrix'>

    See Also
    ========

    eye
    """
    from sparse import MutableSparseMatrix

    cls = kwargs.pop('cls', None)
    if cls is None:
        from dense import Matrix as cls

    if kwargs:
        raise ValueError('unrecognized keyword%s: %s' % (
            's' if len(kwargs) > 1 else '',
            ', '.join(kwargs.keys())))
    rows = 0
    cols = 0
    values = list(values)
    for i in range(len(values)):
        m = values[i]
        if isinstance(m, MatrixBase):
            rows += m.rows
            cols += m.cols
        elif is_sequence(m):
            m = values[i] = Matrix(m)
            rows += m.rows
#.........这里部分代码省略.........
开发者ID:FireJade,项目名称:sympy,代码行数:101,代码来源:dense.py

示例3: zeros

 def zeros(cls, r, c=None):
     """Return an r x c matrix of zeros, square if c is omitted."""
     if is_sequence(r):
         SymPyDeprecationWarning(
             feature="The syntax zeros([%i, %i])" % tuple(r),
             useinstead="zeros(%i, %i)." % tuple(r),
             issue=3381, deprecated_since_version="0.7.2",
         ).warn()
         r, c = r
     else:
         c = r if c is None else c
     r = as_int(r)
     c = as_int(c)
     return cls._new(r, c, [cls._sympify(0)]*r*c)
开发者ID:alhirzel,项目名称:sympy,代码行数:14,代码来源:dense.py

示例4: _new

 def _new(cls, *args, **kwargs):
     rows, cols, flat_list = cls._handle_creation_inputs(*args, **kwargs)
     self = object.__new__(cls)
     self.rows = rows
     self.cols = cols
     self._mat = list(flat_list)  # create a shallow copy
     return self
开发者ID:alhirzel,项目名称:sympy,代码行数:7,代码来源:dense.py

示例5: eye

def eye(n, cls=None):
    """Create square identity matrix n x n

    See Also
    ========

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

示例6: zeros

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:FireJade,项目名称:sympy,代码行数:14,代码来源:dense.py

示例7: __new__

 def __new__(cls, *args, **kwargs):
     return cls._new(*args, **kwargs)
开发者ID:FireJade,项目名称:sympy,代码行数:2,代码来源:dense.py

示例8: eye

 def eye(cls, n):
     """Return an n x n identity matrix."""
     n = as_int(n)
     mat = [cls._sympify(0)]*n*n
     mat[::n + 1] = [cls._sympify(1)]*n
     return cls._new(n, n, mat)
开发者ID:alhirzel,项目名称:sympy,代码行数:6,代码来源:dense.py


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