librosa.util.shear

librosa.util.shear(X, *, factor=1, axis=-1)[source]

Shear a matrix by a given factor.

The column X[:, n] will be displaced (rolled) by factor * n

This is primarily useful for converting between lag and recurrence representations: shearing with factor=-1 converts the main diagonal to a horizontal. Shearing with factor=1 converts a horizontal to a diagonal.

Parameters:
Xnp.ndarray [ndim=2] or scipy.sparse matrix

The array to be sheared

factorinteger

The shear factor: X[:, n] -> np.roll(X[:, n], factor * n)

axisinteger

The axis along which to shear

Returns:
X_shearsame type as X

The sheared matrix

Examples

>>> E = np.eye(3)
>>> librosa.util.shear(E, factor=-1, axis=-1)
array([[1., 1., 1.],
       [0., 0., 0.],
       [0., 0., 0.]])
>>> librosa.util.shear(E, factor=-1, axis=0)
array([[1., 0., 0.],
       [1., 0., 0.],
       [1., 0., 0.]])
>>> librosa.util.shear(E, factor=1, axis=-1)
array([[1., 0., 0.],
       [0., 0., 1.],
       [0., 1., 0.]])