def pair_wise_flip_flopping(W):
    """Determine if a unique walk matrix demonstrates pair-wise flip-flopping.

    Pair-wise flip-flopping is defined as:
    For every pair of classes C[i] and C[j], there exist walk lengths L[x]
    and L[y], such that C[i] has more closed walks of length L[x] than
    C[j] and vice versa.

    Parameters
    ----------
    W : Numpy Matrix
        Unique walk matrix as returned by `walk_classes`

    Returns
    -------
    boolean
        True if pair-wise flip-flopping holds for `W`
    """
    # Work with an ndarray representation of W
    w = W.getA()

    # Get the number of rows and columns in W
    num_rows, num_cols = w.shape

    # Generate all possible pairs of classes and k-walks
    # A single pair is held as a tuple (x, y)
    classes, walks = ([
        (i, j)
        for i in range(0, num)
        for j in range(i + 1, num)
    ] for num in [num_rows, num_cols])

    # Iterate over all pairs of classes
    for cls1, cls2 in classes:

        # Whether these two classes flip-flop at any point
        flip_flops = False

        # Iterate over all pairs of walks
        for w1, w2 in walks:

            # Comparison of classes for k-walk 1
            n1 = w[cls1][w1] - w[cls2][w1]

            # Comparison of classes for k-walk 2
            n2 = w[cls1][w2] - w[cls2][w2]

            # Check to see if the classes flip-flopped
            if (n1 > 0 and n2 < 0) or (n1 < 0 and n2 > 0):
                flip_flops = True
                break

        # If the classes don't flip-flop, return false immediately
        if not flip_flops:
            return False

    # Return true if no counter examples are found
    return True