def ravel_index(ix, shape):
    """
    "Flattens" the 2D input index into a single index on the flattened matrix, similar to np.ravel_multi_index.

    Parameters
    ----------
    ix: array or list of ints of shape (2,)
        The 2D input index.
    shape: list or tuple of ints of length 2
        The shape of the corresponding matrix.

    Returns
    -------
    int between 0 and shape[0]*shape[1]-1
        The index on the flattened matrix corresponding to the 2D input index.

    """
    return ix[0]*shape[1] + ix[1]