liana.utils.neg_to_zero

Contents

liana.utils.neg_to_zero#

liana.utils.neg_to_zero(X, cutoff=0)#

Set negative values to 0.

Parameters:
  • X (Union[Buffer, _SupportsArray[dtype[Any]], _NestedSequence[_SupportsArray[dtype[Any]]], complex, bytes, str, _NestedSequence[complex | bytes | str]]) – Data to be transformed.

  • cutoff (float (default: 0)) – Cutoff value for zero-inflation - values less than this are set to 0. Default is 0.

Return type:

csr_matrix

Returns:

The modified data matrix

Examples

>>> x = np.array([-1, -0.5, 0.1, 0.4, 2])
>>> print(neg_to_zero(x))
<Compressed Sparse Row sparse matrix of dtype 'float64'
        with 5 stored elements and shape (1, 5)>
Coords        Values
(0, 0)        0.0
(0, 1)        0.0
(0, 2)        0.1
(0, 3)        0.4
(0, 4)        2.0
>>> print(neg_to_zero(x, cutoff=0.5))
<Compressed Sparse Row sparse matrix of dtype 'float64'
        with 5 stored elements and shape (1, 5)>
Coords        Values
(0, 0)        0.0
(0, 1)        0.0
(0, 2)        0.0
(0, 3)        0.0
(0, 4)        2.0