egttools.utils.spmatrix

class spmatrix[source]

Bases: object

This 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

asfptype

Upcast matrix to a floating point format (if necessary)

getH

Return the Hermitian transpose of this matrix.

get_shape

Get the shape of the matrix

getcol

Returns a copy of column j of the matrix, as an (m x 1) sparse matrix (column vector).

getformat

Matrix storage format

getmaxprint

Maximum number of elements to display when printed.

getnnz

Number of stored values, including explicit zeros.

getrow

Returns a copy of row i of the matrix, as a (1 x n) sparse matrix (row vector).

set_shape

Set the shape of the matrix in-place

todense

Return a dense representation of this sparse matrix.

Attributes

shape

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:

types.GenericAlias

Examples

>>> import numpy as np
>>> from scipy.sparse import coo_matrix
>>> coo_matrix[np.int8]
scipy.sparse._coo.coo_matrix[numpy.int8]
__mul__(other)[source]
__pow__(power)[source]
__rmul__(other)[source]
asfptype()[source]

Upcast matrix to a floating point format (if necessary)

getH()[source]

Return the Hermitian transpose of this matrix.

See also

numpy.matrix.getH

NumPy’s implementation of getH for matrices

get_shape()[source]

Get the shape of the matrix

getcol(j)[source]

Returns a copy of column j of the matrix, as an (m x 1) sparse matrix (column vector).

getformat()[source]

Matrix storage format

getmaxprint()[source]

Maximum number of elements to display when printed.

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.

getrow(i)[source]

Returns a copy of row i of the matrix, as a (1 x n) sparse matrix (row vector).

set_shape(shape)[source]

Set the shape of the matrix in-place

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