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)

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 .