Linalg (utils.linalg)¶

Linear algebra helper routines and wrapper functions for handling sparse matrices and dense matrices representation.

nimfa.utils.linalg.all(X, axis=None)

Test whether all elements along a given axis of sparse or dense matrix :param:`X` are nonzero.

Parameters: X (scipy.sparse of format csr, csc, coo, bsr, dok, lil, dia) – Target matrix.

or numpy.matrix :param axis: Specified axis along which nonzero test is performed. If :param:`axis` not specified, whole matrix is considered. :type axis: int

nimfa.utils.linalg.any(X, axis=None)

Test whether any element along a given axis of sparse or dense matrix X is nonzero.

Parameters: X (scipy.sparse of format csr, csc, coo, bsr, dok, lil,) – Target matrix.

dia or numpy.matrix :param axis: Specified axis along which nonzero test is performed. If :param:`axis` not specified, whole matrix is considered. :type axis: int

nimfa.utils.linalg.argmax(X, axis=None)

Return tuple (values, indices) of the maximum entries of matrix :param:`X` along axis :param:`axis`. Row major order.

Parameters: X (scipy.sparse of format csr, csc, coo, bsr, dok, lil,) – Target matrix.

dia or numpy.matrix :param axis: Specify axis along which to operate. If not specified, whole matrix :param:`X` is considered. :type axis: int

nimfa.utils.linalg.argmin(X, axis=None)

Return tuple (values, indices) of the minimum entries of matrix :param:`X` along axis :param:`axis`. Row major order.

Parameters: X (scipy.sparse of format csr, csc, coo, bsr, dok, lil,) – Target matrix.

dia or numpy.matrix :param axis: Specify axis along which to operate. If not specified, whole matrix :param:`X` is considered. :type axis: int

nimfa.utils.linalg.choose(n, k)

A fast way to calculate binomial coefficients C(n, k). It is 10 times faster than scipy.mis.comb for exact answers.

Parameters: n (int) – Index of binomial coefficient. k (int) – Index of binomial coefficient.
nimfa.utils.linalg.count(X, s)

Return the number of occurrences of element :param:`s` in sparse or dense matrix X.

Parameters: X (scipy.sparse of format csr, csc, coo, bsr, dok, lil, dia) – The input matrix.

or numpy.matrix :param s: the input scalar. :type s: float

nimfa.utils.linalg.diff(X)

Compute differences between adjacent elements of X.

Parameters: X (numpy.matrix) – Vector for which consecutive differences are computed.
nimfa.utils.linalg.dot(X, Y)

Compute dot product of matrices :param:`X` and :param:`Y`.

Parameters: X (scipy.sparse of format csr, csc, coo, bsr, dok, lil, dia) – First input matrix.

or numpy.matrix :param Y: Second input matrix. :type Y: scipy.sparse of format csr, csc, coo, bsr, dok, lil, dia or numpy.matrix

nimfa.utils.linalg.elop(X, Y, op)

Compute element-wise operation of matrix :param:`X` and matrix :param:`Y`.

Parameters: X (scipy.sparse of format csr, csc, coo, bsr, dok, lil, dia) – First input matrix.

or numpy.matrix :param Y: Second input matrix. :type Y: scipy.sparse of format csr, csc, coo, bsr, dok, lil, dia or numpy.matrix :param op: Operation to be performed. :type op: func

nimfa.utils.linalg.find(X)

Return all nonzero elements indices (linear indices) of sparse or dense matrix :param:`X`. It is Matlab notation.

Parameters: X – Target matrix.

type X: scipy.sparse of format csr, csc, coo, bsr, dok, lil, dia or numpy.matrix

nimfa.utils.linalg.hstack(X, format=None, dtype=None)

Stack sparse or dense matrices horizontally (column wise).

Parameters: X (sequence of scipy.sparse of format csr, csc, coo, bsr,) – Sequence of matrices with compatible shapes.

dok, lil, dia or numpy.matrix

nimfa.utils.linalg.inf_norm(X)

Infinity norm of a matrix (maximum absolute row sum).

Parameters: X (scipy.sparse.csr_matrix, scipy.sparse.csc_matrix) – Input matrix.

or numpy.matrix

nimfa.utils.linalg.inv_svd(X)

Compute matrix inversion using SVD.

Parameters: X (scipy.sparse or numpy.matrix) – The input matrix.
nimfa.utils.linalg.max(X, s)

Compute element-wise max(x,s) assignment for sparse or dense matrix.

Parameters: X (scipy.sparse of format csr, csc, coo, bsr, dok, lil, dia) – The input matrix.

or numpy.matrix :param s: the input scalar. :type s: float

nimfa.utils.linalg.min(X, s)

Compute element-wise min(x,s) assignment for sparse or dense matrix.

Parameters: X (scipy.sparse of format csr, csc, coo, bsr, dok, lil, dia) – The input matrix.

or numpy.matrix :param s: the input scalar. :type s: float

nimfa.utils.linalg.multiply(X, Y)

Compute element-wise multiplication of matrices :param:`X` and :param:`Y`.

Parameters: X (scipy.sparse of format csr, csc, coo, bsr, dok, lil, dia) – First input matrix.

or numpy.matrix :param Y: Second input matrix. :type Y: scipy.sparse of format csr, csc, coo, bsr, dok, lil, dia or numpy.matrix

nimfa.utils.linalg.negative(X)

Check if :param:`X` contains negative elements.

Parameters: X (scipy.sparse of format csr, csc, coo, bsr, dok, lil,) – Target matrix.

dia or numpy.matrix

nimfa.utils.linalg.norm(X, p='fro')

Compute entry-wise norms (! not induced/operator norms).

Parameters: X (scipy.sparse of format csr, csc, coo, bsr, dok, lil, dia) – The input matrix.

or numpy.matrix :param p: Order of the norm. :type p: str or float

nimfa.utils.linalg.nz_data(X)

Return list of nonzero elements from X (! data, not indices).

Parameters: X (scipy.sparse of format csr, csc, coo, bsr, dok, lil, dia) – The input matrix.

or numpy.matrix

nimfa.utils.linalg.power(X, s)

Compute matrix power of matrix :param:`X` for power :param:`s`.

Parameters: X (scipy.sparse of format csr, csc, coo, bsr, dok, lil, dia) – Input matrix.

or numpy.matrix :param s: Power. :type s: int

nimfa.utils.linalg.repmat(X, m, n)

Construct matrix consisting of an m-by-n tiling of copies of X.

Parameters: X (scipy.sparse of format csr, csc, coo, bsr, dok, lil,) – The input matrix.

dia or numpy.matrix :param m,n: The number of repetitions of :param:`X` along each axis. :type m,n: int

nimfa.utils.linalg.sop(X, s=None, op=None)

Compute scalar element wise operation of matrix :param:`X` and scalar :param:`s`.

Parameters: X (scipy.sparse of format csr, csc, coo, bsr, dok, lil, dia) – The input matrix.

or numpy.matrix :param s: Input scalar. If not specified, element wise operation of input matrix is computed. :type s: float :param op: Operation to be performed. :type op: func

nimfa.utils.linalg.sort(X)

Return sorted elements of :param:`X` and array of corresponding sorted indices.

Parameters: X (scipy.sparse of format csr, csc, coo, bsr, dok, lil,) – Target vector.

dia or numpy.matrix

nimfa.utils.linalg.std(X, axis=None, ddof=0)

Compute the standard deviation along the specified :param:`axis` of matrix :param:`X`.

Parameters: X (scipy.sparse of format csr, csc, coo, bsr, dok, lil,) – Target matrix.

dia or numpy.matrix :param axis: Axis along which deviation is computed. If not specified, whole matrix :param:`X` is considered. :type axis: int :param ddof: Means delta degrees of freedom. The divisor used in computation is N - :param:`ddof`, where N represents the number of elements. Default is 0. :type ddof: float

nimfa.utils.linalg.sub2ind(shape, row_sub, col_sub)

Return the linear index equivalents to the row and column subscripts for given matrix shape.

Parameters: shape (tuple) – Preferred matrix shape for subscripts conversion. row_sub (list) – Row subscripts. col_sub (list) – Column subscripts.
nimfa.utils.linalg.svd(X)

Compute standard SVD on matrix X.

Parameters: X (scipy.sparse of format csr, csc, coo, bsr, dok, lil,) – The input matrix.

dia or numpy.matrix

nimfa.utils.linalg.trace(X)

Return trace of sparse or dense square matrix X.

Parameters: X (scipy.sparse of format csr, csc, coo, bsr, dok, lil,) – Target matrix.

dia or numpy.matrix

nimfa.utils.linalg.vstack(X, format=None, dtype=None)

Stack sparse or dense matrices vertically (row wise).

Parameters: X (sequence of scipy.sparse of format csr, csc, coo, bsr,) – Sequence of matrices with compatible shapes.

dok, lil, dia or numpy.matrix