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


Python ImmutableMatrix._new方法代碼示例

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


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

示例1: as_immutable

# 需要導入模塊: from immutable import ImmutableMatrix [as 別名]
# 或者: from immutable.ImmutableMatrix import _new [as 別名]
 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,代碼行數:9,代碼來源:dense.py

示例2: zeros

# 需要導入模塊: from immutable import ImmutableMatrix [as 別名]
# 或者: from immutable.ImmutableMatrix import _new [as 別名]
 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, [S.Zero]*r*c)
開發者ID:FireJade,項目名稱:sympy,代碼行數:16,代碼來源:dense.py

示例3: __new__

# 需要導入模塊: from immutable import ImmutableMatrix [as 別名]
# 或者: from immutable.ImmutableMatrix import _new [as 別名]
 def __new__(cls, *args, **kwargs):
     return cls._new(*args, **kwargs)
開發者ID:FireJade,項目名稱:sympy,代碼行數:4,代碼來源:dense.py

示例4: eye

# 需要導入模塊: from immutable import ImmutableMatrix [as 別名]
# 或者: from immutable.ImmutableMatrix import _new [as 別名]
 def eye(cls, n):
     """Return an n x n identity matrix."""
     n = as_int(n)
     mat = [S.Zero]*n*n
     mat[::n + 1] = [S.One]*n
     return cls._new(n, n, mat)
開發者ID:FireJade,項目名稱:sympy,代碼行數:8,代碼來源:dense.py

示例5: diag

# 需要導入模塊: from immutable import ImmutableMatrix [as 別名]
# 或者: from immutable.ImmutableMatrix import _new [as 別名]

#.........這裏部分代碼省略.........
    [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
            cols += m.cols
        else:
            rows += 1
            cols += 1
    res = MutableSparseMatrix.zeros(rows, cols)
    i_row = 0
    i_col = 0
    for m in values:
        if isinstance(m, MatrixBase):
            res[i_row:i_row + m.rows, i_col:i_col + m.cols] = m
            i_row += m.rows
            i_col += m.cols
        else:
            res[i_row, i_col] = m
            i_row += 1
            i_col += 1
    return cls._new(res)
開發者ID:FireJade,項目名稱:sympy,代碼行數:104,代碼來源:dense.py

示例6: eye

# 需要導入模塊: from immutable import ImmutableMatrix [as 別名]
# 或者: from immutable.ImmutableMatrix import _new [as 別名]
 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,代碼行數:8,代碼來源:dense.py


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