def is_isomorphic(T1, T2):
 T1 = np.asarray(T1, order='c')
 T2 = np.asarray(T2, order='c')
 if (type(T1) != np.ndarray):
  raise TypeError('T1 must be a numpy array.')
 if (type(T2) != np.ndarray):
  raise TypeError('T2 must be a numpy array.')
 T1S = T1.shape
 T2S = T2.shape
 if (len(T1S) != 1):
  raise ValueError('T1 must be one-dimensional.')
 if (len(T2S) != 1):
  raise ValueError('T2 must be one-dimensional.')
 if (T1S[0] != T2S[0]):
  raise ValueError('T1 and T2 must have the same number of elements.')
 n = T1S[0]
 d1 = {}
 d2 = {}
 for i in xrange(0, n):
  if (T1[i] in d1):
   if (not (T2[i] in d2)):
    return False
   if ((d1[T1[i]] != T2[i]) or (d2[T2[i]] != T1[i])):
    return False
  elif (T2[i] in d2):
   return False
  else:
   d1[T1[i]] = T2[i]
   d2[T2[i]] = T1[i]
 return True

def is_isomorphic ( T1 , T2 ) : T1 = np . asarray ( T1 , order = 'c' ) T2 = np . asarray ( T2 , order = 'c' ) if ( type ( T1 ) != np . ndarray ) : raise TypeError ( 'T1 must be a numpy array.' ) if ( type ( T2 ) != np . ndarray ) : raise TypeError ( 'T2 must be a numpy array.' ) T1S = T1 . shape T2S = T2 . shape if ( len ( T1S ) != 1 ) : raise ValueError ( 'T1 must be one-dimensional.' ) if ( len ( T2S ) != 1 ) : raise ValueError ( 'T2 must be one-dimensional.' ) if ( T1S [ 0 ] != T2S [ 0 ] ) : raise ValueError ( 'T1 and T2 must have the same number of elements.' ) n = T1S [ 0 ] d1 = { } d2 = { } for i in xrange ( 0 , n ) : if ( T1 [ i ] in d1 ) : if ( not ( T2 [ i ] in d2 ) ) : return False if ( ( d1 [ T1 [ i ] ] != T2 [ i ] ) or ( d2 [ T2 [ i ] ] != T1 [ i ] ) ) : return False elif ( T2 [ i ] in d2 ) : return False else : d1 [ T1 [ i ] ] = T2 [ i ] d2 [ T2 [ i ] ] = T1 [ i ] return True
determines if two different cluster assignments are equivalent .