egttools.utils.spmatrix¶
- class spmatrix[source]¶
Bases:
objectThis class provides a base class for all sparse matrix classes.
Warning
SciPy sparse is shifting from a sparse matrix interface to a sparse array interface. In the next few releases we expect to deprecate the sparse matrix interface. For documentation of the matrix interface, see the spmatrix interface docs. For guidance on converting existing code to sparse arrays, see Migration from spmatrix to sparray.
This class also serves as the namespace for SciPy sparse matrix types. It cannot be instantiated. Most of the work is provided by subclasses.
Methods
Upcast matrix to a floating point format (if necessary)
Return the Hermitian transpose of this matrix.
Get the shape of the matrix
Returns a copy of column j of the matrix, as an (m x 1) sparse matrix (column vector).
Matrix storage format
Maximum number of elements to display when printed.
Number of stored values, including explicit zeros.
Returns a copy of row i of the matrix, as a (1 x n) sparse matrix (row vector).
Set the shape of the matrix in-place
Return a dense representation of this sparse matrix.
Attributes
Shape of the matrix
- classmethod __class_getitem__(arg, /)[source]¶
Return a parametrized wrapper around the ~scipy.sparse.spmatrix type.
Added in version 1.16.0.
- Returns:
alias – A parametrized ~scipy.sparse.spmatrix type.
- Return type:
Examples
>>> import numpy as np >>> from scipy.sparse import coo_matrix
>>> coo_matrix[np.int8] scipy.sparse._coo.coo_matrix[numpy.int8]
- getH()[source]¶
Return the Hermitian transpose of this matrix.
See also
numpy.matrix.getHNumPy’s implementation of getH for matrices
- getcol(j)[source]¶
Returns a copy of column j of the matrix, as an (m x 1) sparse matrix (column vector).
- getnnz(axis=None)[source]¶
Number of stored values, including explicit zeros.
- Parameters:
axis (None, 0, or 1) – Select between the number of values across the whole array, in each column, or in each row.
- todense(order=None, out=None)[source]¶
Return a dense representation of this sparse matrix.
- Parameters:
order ({'C', 'F'}, optional) – Whether to store multi-dimensional data in C (row-major) or Fortran (column-major) order in memory. The default is ‘None’, which provides no ordering guarantees. Cannot be specified in conjunction with the out argument.
out (ndarray, 2-D, optional) – If specified, uses this array (or numpy.matrix) as the output buffer instead of allocating a new array to return. The provided array must have the same shape and dtype as the sparse matrix on which you are calling the method.
- Returns:
arr – A NumPy matrix object with the same shape and containing the same data represented by the sparse matrix, with the requested memory order. If out was passed and was an array (rather than a numpy.matrix), it will be filled with the appropriate values and returned wrapped in a numpy.matrix object that shares the same memory.
- Return type:
numpy.matrix, 2-D
- __annotations__ = {'_allow_nd': tuple[int, ...]}¶
- property shape¶
Shape of the matrix