def persistence(S):
    """
    This function computes the persistence for a given multilayer partition S
    defined in  "Community detection in temporal multilayer networks, and ...
    its application to correlation networks" (http://arxiv.org/abs/1501.00040)

    Inputs
    ======
    S: pxn matrix, n is the numebr of partitions, p is the number of nodes

    Outputs
    =======
    pers: the persistence value
    """

    pers = (S[:, 1::] == S[:, 0:-1]).sum()

    return pers