topact.sparsetools

Tools for manipulating sparse matrices.

Module Contents

Functions

rescale(matrix, factors[, axis])

rescale_rows(matrix, factors)

rescale_columns(matrix, factors)

iterate_sparse(matrix)

Yields all entries in the matrix along with their indices.

filter_cols(matrix, keep_indices)

Returns the input matrix with only columns from the given indices.

topact.sparsetools.rescale(matrix, factors, axis=0)
Parameters
  • factors (Sequence[float]) –

  • axis (int) –

topact.sparsetools.rescale_rows(matrix, factors)
Parameters

factors (Sequence[float]) –

topact.sparsetools.rescale_columns(matrix, factors)
Parameters

factors (Sequence[float]) –

topact.sparsetools.iterate_sparse(matrix)

Yields all entries in the matrix along with their indices.

Parameters

matrix – A sparse array.

Yields

The tuples (i, j, v = matrix[i,j]) for all non-zero entries v.

Raises

NotImplementedError – If the matrix is not in csc or csr format.

Return type

Iterator[tuple[int, int, Any]]

topact.sparsetools.filter_cols(matrix, keep_indices)

Returns the input matrix with only columns from the given indices.

Parameters
  • matrix – A sparse array.

  • keep_indices (Collection[int]) – Column indices.

Returns

A matrix with the same entries as the input, but with only the specified columns.