sparse.compressed

Base class for sparse matrix formats using compressed storage.

Module Contents

Classes

_cs_matrix(self,arg1,shape=None,dtype=None,copy=False) base matrix class for compressed row and column oriented matrices
class _cs_matrix(arg1, shape=None, dtype=None, copy=False)

base matrix class for compressed row and column oriented matrices

__init__(arg1, shape=None, dtype=None, copy=False)
getnnz(axis=None)
_set_self(other, copy=False)

take the member variables of other and assign them to self

check_format(full_check=True)

check whether the matrix format is valid

full_check : bool, optional
If True, rigorous check, O(N) operations. Otherwise basic check, O(1) operations (default True).
_scalar_binopt(other, op)

Scalar version of self._binopt, for cases in which no new nonzeros are added. Produces a new spmatrix in canonical form.

__eq__(other)
__ne__(other)
_inequality(other, op, op_name, bad_scalar_msg)
__lt__(other)
__gt__(other)
__le__(other)
__ge__(other)
_add_dense(other)
_add_sparse(other)
_sub_sparse(other)
multiply(other)

Point-wise multiplication by another matrix, vector, or scalar.

_mul_vector(other)
_mul_multivector(other)
_mul_sparse_matrix(other)
diagonal(k=0)
_maximum_minimum(other, npop, op_name, dense_check)
maximum(other)
minimum(other)
sum(axis=None, dtype=None, out=None)

Sum the matrix over the given axis. If the axis is None, sum over both rows and columns, returning a scalar.

_minor_reduce(ufunc)

Reduce nonzeros with a ufunc over the minor axis when non-empty

Warning: this does not call sum_duplicates()

major_index : array of ints
Major indices where nonzero
value : array of self.dtype
Reduce result for nonzeros in each major_index
__setitem__(index, x)
_setdiag(values, k)
_prepare_indices(i, j)
_set_many(i, j, x)

Sets value at each (i, j) to x

Here (i,j) index major and minor respectively, and must not contain duplicate entries.

_zero_many(i, j)

Sets value at each (i, j) to zero, preserving sparsity structure.

Here (i,j) index major and minor respectively.

_insert_many(i, j, x)

Inserts new nonzero at each (i, j) with value x

Here (i,j) index major and minor respectively. i, j and x must be non-empty, 1d arrays. Inserts each major group (e.g. all entries per row) at a time. Maintains has_sorted_indices property. Modifies i, j, x in place.

_get_single_element(row, col)
_get_submatrix(slice0, slice1)

Return a submatrix of this matrix (new matrix is created).

tocoo(copy=True)
toarray(order=None, out=None)
eliminate_zeros()

Remove zero entries from the matrix

This is an in place operation

__get_has_canonical_format()

Determine whether the matrix has sorted indices and no duplicates

Returns
  • True: if the above applies
  • False: otherwise

has_canonical_format implies has_sorted_indices, so if the latter flag is False, so will the former be; if the former is found True, the latter flag is also set.

__set_has_canonical_format(val)
sum_duplicates()

Eliminate duplicate matrix entries by adding them together

The is an in place operation

__get_sorted()

Determine whether the matrix has sorted indices

Returns
  • True: if the indices of the matrix are in sorted order
  • False: otherwise
__set_sorted(val)
sorted_indices()

Return a copy of this matrix with sorted indices

sort_indices()

Sort the indices of this matrix in place

prune()

Remove empty space after all non-zero elements.

_with_data(data, copy=True)

Returns a matrix with the same sparsity structure as self, but with different data. By default the structure arrays (i.e. .indptr and .indices) are copied.

_binopt(other, op)

apply the binary operation fn to two sparse matrices.

_divide_sparse(other)

Divide this matrix by a second sparse matrix.