Caution

You're reading an old version of this documentation. If you want up-to-date information, please have a look at 0.9.1.

librosa.util.roll_sparse

librosa.util.roll_sparse(x, shift, axis=0)[source]

Sparse matrix roll

This operation is equivalent to numpy.roll, but operates on sparse matrices.

Warning

This function is deprecated in version 0.7.1. It will be removed in version 0.8.0.

Parameters
xscipy.sparse.spmatrix or np.ndarray

The sparse matrix input

shiftint

The number of positions to roll the specified axis

axis(0, 1, -1)

The axis along which to roll.

Returns
x_rolledsame type as x

The rolled matrix, with the same format as x

See also

numpy.roll

Examples

>>> # Generate a random sparse binary matrix
>>> X = scipy.sparse.lil_matrix(np.random.randint(0, 2, size=(5,5)))
>>> X_roll = roll_sparse(X, 2, axis=0)  # Roll by 2 on the first axis
>>> X_dense_r = roll_sparse(X.toarray(), 2, axis=0)  # Equivalent dense roll
>>> np.allclose(X_roll, X_dense_r.toarray())
True