def attribute_ac(M):
    try:
        import numpy
    except ImportError:
        raise ImportError(
          "attribute_assortativity requires NumPy: http://scipy.org/ ")
    if M.sum() != 1.0:
        M=M/float(M.sum())
    M=numpy.asmatrix(M)
    s=(M*M).sum()
    t=M.trace()
    r=(t-s)/(1-s)
    return float(r)
Compute assortativity for attribute matrix M.
dataset/ETHPy150Open networkx/networkx/networkx/algorithms/assortativity/correlation.py/attribute_ac