def rank(X, cond=1e-12):
 X = np.asarray(X)
 if (len(X.shape) == 2):
  D = scipy.linalg.svdvals(X)
  return int(np.add.reduce(np.greater((D / D.max()), cond).astype(np.int32)))
 else:
  return int((not np.alltrue(np.equal(X, 0.0))))

def rank ( X , cond = 1e-12 ) : X = np . asarray ( X ) if ( len ( X . shape ) == 2 ) : D = scipy . linalg . svdvals ( X ) return int ( np . add . reduce ( np . greater ( ( D / D . max ( ) ) , cond ) . astype ( np . int32 ) ) ) else : return int ( ( not np . alltrue ( np . equal ( X , 0.0 ) ) ) )
return the rank of a matrix x based on its generalized inverse .