def precompute_raveled_slices(coeff_shapes, axes=None):
    """Return slices and shapes for raveled multilevel wavelet coefficients.

    The output is equivalent to the ``coeff_slices`` output of
    `pywt.ravel_coeffs`, but this function does not require computing a
    wavelet transform first.

    Parameters
    ----------
    coeff_shapes : array-like
        A list of multilevel wavelet coefficient shapes as returned by
        `pywt.wavedecn_shapes`.
    axes : sequence of ints, optional
        Axes over which the DWT that created ``coeffs`` was performed. The
        default value of None corresponds to all axes.

    Returns
    -------
    coeff_slices : list
        List of slices corresponding to each coefficient. As a 2D example,
        ``coeff_arr[coeff_slices[1]['dd']]`` would extract the first level
        detail coefficients from ``coeff_arr``.

    Examples
    --------
    >>> import pywt
    >>> data_shape = (64, 64)
    >>> coeff_shapes = pywt.wavedecn_shapes(data_shape, wavelet='db2', level=3,
    ...                                     mode='periodization')
    >>> coeff_slices = precompute_raveled_slices(coeff_shapes)
    >>> print(coeff_slices[0])  # approximation coefficients
    slice(None, 64, None)
    >>> d1_coeffs = coeff_slices[-1]  # first level detail coefficients
    >>> (d1_coeffs['ad'], d1_coeffs['da'], d1_coeffs['dd'])
    (slice(1024, 2048, None), slice(2048, 3072, None), slice(3072, 4096, None))
    """
    # initialize with the approximation coefficients.
    a_shape = coeff_shapes[0]
    a_size = np.prod(a_shape)

    if len(coeff_shapes) == 1:
        # only a single approximation coefficient array was found
        return [slice(a_size), ]

    a_slice = slice(a_size)

    # initialize list of coefficient slices
    coeff_slices = []
    coeff_slices.append(a_slice)

    # loop over the detail cofficients, embedding them in coeff_arr
    details_list = coeff_shapes[1:]
    offset = a_size
    for shape_dict in details_list:
        # new dictionaries for detail coefficient slices and shapes
        coeff_slices.append({})
        keys = sorted(shape_dict.keys())
        for key in keys:
            shape = shape_dict[key]
            size = np.prod(shape)
            sl = slice(offset, offset + size)
            offset += size
            coeff_slices[-1][key] = sl
    return coeff_slices
def precompute_raveled_slices ( coeff_shapes , axes = None ) : a_shape = coeff_shapes [ 0 ] a_size = np . prod ( a_shape ) if len ( coeff_shapes ) == 1 : return [ slice ( a_size ) , ] a_slice = slice ( a_size ) coeff_slices = [ ] coeff_slices . append ( a_slice ) details_list = coeff_shapes [ 1 : ] offset = a_size for shape_dict in details_list : coeff_slices . append ( { } ) keys = sorted ( shape_dict . keys ( ) ) for key in keys : shape = shape_dict [ key ] size = np . prod ( shape ) sl = slice ( offset , offset + size ) offset += size coeff_slices [ - 1 ] [ key ] = sl return coeff_slices
Return slices and shapes for raveled multilevel wavelet coefficients.

    The output is equivalent to the ``coeff_slices`` output of
    `pywt.ravel_coeffs`, but this function does not require computing a
    wavelet transform first.

    Parameters
    ----------
    coeff_shapes : array-like
        A list of multilevel wavelet coefficient shapes as returned by
        `pywt.wavedecn_shapes`.
    axes : sequence of ints, optional
        Axes over which the DWT that created ``coeffs`` was performed. The
        default value of None corresponds to all axes.

    Returns
    -------
    coeff_slices : list
        List of slices corresponding to each coefficient. As a 2D example,
        ``coeff_arr[coeff_slices[1]['dd']]`` would extract the first level
        detail coefficients from ``coeff_arr``.

    Examples
    --------
    >>> import pywt
    >>> data_shape = (64, 64)
    >>> coeff_shapes = pywt.wavedecn_shapes(data_shape, wavelet='db2', level=3,
    ...                                     mode='periodization')
    >>> coeff_slices = precompute_raveled_slices(coeff_shapes)
    >>> print(coeff_slices[0])  # approximation coefficients
    slice(None, 64, None)
    >>> d1_coeffs = coeff_slices[-1]  # first level detail coefficients
    >>> (d1_coeffs['ad'], d1_coeffs['da'], d1_coeffs['dd'])
    (slice(1024, 2048, None), slice(2048, 3072, None), slice(3072, 4096, None))