librosa.core.fill_off_diagonal¶
-
librosa.core.fill_off_diagonal(x, radius, value=0)[source]¶ Sets all cells of a matrix to a given
valueif they lie outside a constraint region. In this case, the constraint region is the Sakoe-Chiba band which runs with a fixedradiusalong the main diagonal. Whenx.shape[0] != x.shape[1], the radius will be expanded so thatx[-1, -1] = 1always.xwill be modified in place.Parameters: - x : np.ndarray [shape=(N, M)]
Input matrix, will be modified in place.
- radius : float
The band radius (1/2 of the width) will be
int(radius*min(x.shape)).- value : int
x[n, m] = valuewhen(n, m)lies outside the band.
Examples
>>> x = np.ones((8, 8)) >>> global_constraints(x, 0.25) >>> x array([[1, 1, 0, 0, 0, 0, 0, 0], [1, 1, 1, 0, 0, 0, 0, 0], [0, 1, 1, 1, 0, 0, 0, 0], [0, 0, 1, 1, 1, 0, 0, 0], [0, 0, 0, 1, 1, 1, 0, 0], [0, 0, 0, 0, 1, 1, 1, 0], [0, 0, 0, 0, 0, 1, 1, 1], [0, 0, 0, 0, 0, 0, 1, 1]]) >>> x = np.ones((8, 12)) >>> global_constraints(x, 0.25) >>> x array([[1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0], [1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0], [0, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0], [0, 0, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0], [0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 0, 0], [0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 0], [0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1], [0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1]])