def numeric_ac(M):
    # M is a numpy matrix or array
    # numeric assortativity coefficient, pearsonr
    try:
        import numpy
    except __HOLE__:
        raise ImportError('numeric_assortativity requires ',
                          'NumPy: http://scipy.org/')
    if M.sum() != 1.0:
        M=M/float(M.sum())
    nx,ny=M.shape # nx=ny
    x=numpy.arange(nx)
    y=numpy.arange(ny)
    a=M.sum(axis=0)
    b=M.sum(axis=1)
    vara=(a*x**2).sum()-((a*x).sum())**2
    varb=(b*x**2).sum()-((b*x).sum())**2
    xy=numpy.outer(x,y)
    ab=numpy.outer(a,b)
    return (xy*(M-ab)).sum()/numpy.sqrt(vara*varb)


# fixture for nose tests
dataset/ETHPy150Open networkx/networkx/networkx/algorithms/assortativity/correlation.py/numeric_ac