Caution

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

# librosa.util.index_to_slice

Generate a slice array from an index array.

Parameters:
idxlist-like

Array of index boundaries

idx_min, idx_maxNone or int

Minimum and maximum allowed indices

stepNone or int

Step size for each slice. If None, then the default step of 1 is used.

If True, pad `idx` to span the range `idx_min:idx_max`.

Returns:
sliceslist of slice

`slices[i] = slice(idx[i], idx[i+1], step)` Additional slice objects may be added at the beginning or end, depending on whether `pad==True` and the supplied values for `idx_min` and `idx_max`.

Examples

```>>> # Generate slices from spaced indices
>>> librosa.util.index_to_slice(np.arange(20, 100, 15))
[slice(20, 35, None), slice(35, 50, None), slice(50, 65, None), slice(65, 80, None),
slice(80, 95, None)]
>>> # Pad to span the range (0, 100)
>>> librosa.util.index_to_slice(np.arange(20, 100, 15),
...                             idx_min=0, idx_max=100)
[slice(0, 20, None), slice(20, 35, None), slice(35, 50, None), slice(50, 65, None),
slice(65, 80, None), slice(80, 95, None), slice(95, 100, None)]
>>> # Use a step of 5 for each slice
>>> librosa.util.index_to_slice(np.arange(20, 100, 15),
...                             idx_min=0, idx_max=100, step=5)
[slice(0, 20, 5), slice(20, 35, 5), slice(35, 50, 5), slice(50, 65, 5), slice(65, 80, 5),
slice(80, 95, 5), slice(95, 100, 5)]
```