

@cache
def zero_crossings(y, threshold=1e-10, ref_magnitude=None, pad=True, zero_pos=True, axis=(- 1)):
    'Find the zero-crossings of a signal `y`: indices `i` such that\n    `sign(y[i]) != sign(y[j])`.\n\n    If `y` is multi-dimensional, then zero-crossings are computed along\n    the specified `axis`.\n\n    Examples\n    --------\n    >>> # Generate a time-series\n    >>> y = np.sin(np.linspace(0, 4 * 2 * np.pi, 20))\n    >>> y\n    array([  0.000e+00,   9.694e-01,   4.759e-01,  -7.357e-01,\n            -8.372e-01,   3.247e-01,   9.966e-01,   1.646e-01,\n            -9.158e-01,  -6.142e-01,   6.142e-01,   9.158e-01,\n            -1.646e-01,  -9.966e-01,  -3.247e-01,   8.372e-01,\n             7.357e-01,  -4.759e-01,  -9.694e-01,  -9.797e-16])\n    >>> # Compute zero-crossings\n    >>> z = librosa.zero_crossings(y)\n    >>> z\n    array([ True, False, False,  True, False,  True, False, False,\n            True, False,  True, False,  True, False, False,  True,\n           False,  True, False,  True], dtype=bool)\n    >>> # Stack y against the zero-crossing indicator\n    >>> np.vstack([y, z]).T\n    array([[  0.000e+00,   1.000e+00],\n           [  9.694e-01,   0.000e+00],\n           [  4.759e-01,   0.000e+00],\n           [ -7.357e-01,   1.000e+00],\n           [ -8.372e-01,   0.000e+00],\n           [  3.247e-01,   1.000e+00],\n           [  9.966e-01,   0.000e+00],\n           [  1.646e-01,   0.000e+00],\n           [ -9.158e-01,   1.000e+00],\n           [ -6.142e-01,   0.000e+00],\n           [  6.142e-01,   1.000e+00],\n           [  9.158e-01,   0.000e+00],\n           [ -1.646e-01,   1.000e+00],\n           [ -9.966e-01,   0.000e+00],\n           [ -3.247e-01,   0.000e+00],\n           [  8.372e-01,   1.000e+00],\n           [  7.357e-01,   0.000e+00],\n           [ -4.759e-01,   1.000e+00],\n           [ -9.694e-01,   0.000e+00],\n           [ -9.797e-16,   1.000e+00]])\n    >>> # Find the indices of zero-crossings\n    >>> np.nonzero(z)\n    (array([ 0,  3,  5,  8, 10, 12, 15, 17, 19]),)\n\n\n    Parameters\n    ----------\n    y : np.ndarray\n        The input array\n\n    threshold : float > 0 or None\n        If specified, values where `-threshold <= y <= threshold` are\n        clipped to 0.\n\n    ref_magnitude : float > 0 or callable\n        If numeric, the threshold is scaled relative to `ref_magnitude`.\n\n        If callable, the threshold is scaled relative to\n        `ref_magnitude(np.abs(y))`.\n\n    pad : boolean\n        If `True`, then `y[0]` is considered a valid zero-crossing.\n\n    zero_pos : boolean\n        If `True` then the value 0 is interpreted as having positive sign.\n\n        If `False`, then 0, -1, and +1 all have distinct signs.\n\n    axis : int\n        Axis along which to compute zero-crossings.\n\n    Returns\n    -------\n    zero_crossings : np.ndarray [shape=y.shape, dtype=boolean]\n        Indicator array of zero-crossings in `y` along the selected axis.\n    '
    if (threshold is None):
        threshold = 0.0
    if six.callable(ref_magnitude):
        threshold = (threshold * ref_magnitude(np.abs(y)))
    elif (ref_magnitude is not None):
        threshold = (threshold * ref_magnitude)
    if (threshold > 0):
        y = y.copy()
        y[(np.abs(y) <= threshold)] = 0
    if zero_pos:
        y_sign = np.signbit(y_sign)
    else:
        y_sign = np.sign(y)
    slice_pre = ([slice(None)] * y.ndim)
    slice_pre[axis] = slice(1, None)
    slice_post = ([slice(None)] * y.ndim)
    slice_post[axis] = slice((- 1))
    padding = ([(0, 0)] * y.ndim)
    padding[axis] = (1, 0)
    return np.pad((y_sign[slice_post] != y_sign[slice_pre]), padding, mode='constant', constant_values=pad)

dataset/ETHPy150Open bmcfee/librosa/librosa/core/audio.py zero_crossings/VarMisuse@143/1509 `y`->`y_sign`