def _onenorm_matrix_power_nnm(A, p):
 if ((int(p) != p) or (p < 0)):
  raise ValueError('expected non-negative integer p')
 p = int(p)
 if ((len(A.shape) != 2) or (A.shape[0] != A.shape[1])):
  raise ValueError('expected A to be like a square matrix')
 v = np.ones((A.shape[0], 1), dtype=float)
 M = A.T
 for i in range(p):
  v = M.dot(v)
 return max(v)

def _onenorm_matrix_power_nnm ( A , p ) : if ( ( int ( p ) != p ) or ( p < 0 ) ) : raise ValueError ( 'expected non-negative integer p' ) p = int ( p ) if ( ( len ( A . shape ) != 2 ) or ( A . shape [ 0 ] != A . shape [ 1 ] ) ) : raise ValueError ( 'expected A to be like a square matrix' ) v = np . ones ( ( A . shape [ 0 ] , 1 ) , dtype = float ) M = A . T for i in range ( p ) : v = M . dot ( v ) return max ( v )
compute the 1-norm of a non-negative integer power of a non-negative matrix .