code: def create_constraints(labels):
      import itertools
      import random
  
      # aggregate indices of same class
      zeros = np.where(y == 0)[0]
      ones = np.where(y == 1)[0]
      twos = np.where(y == 2)[0]
      # make permutations of all those points in the same class
      zeros_ = list(itertools.combinations(zeros, 2))
      ones_ = list(itertools.combinations(ones, 2))
      twos_ = list(itertools.combinations(twos, 2))
      # put them together!
      sim = np.array(zeros_ + ones_ + twos_)
  
      # similarily, put together indices in different classes
      dis = []
      for zero in zeros:
          for one in ones:
              dis.append((zero, one))
          for two in twos:
              dis.append((zero, two))
      for one in ones:
          for two in twos:
              dis.append((one, two))
  
      # pick up just enough dissimilar examples as we have similar examples
      dis = np.array(random.sample(dis, len(sim)))
  
      # return an array of pairs of indices of shape=(2*len(sim), 2), and the
      # corresponding labels, array of shape=(2*len(sim))
      # Each pair of similar points have a label of +1 and each pair of
      # dissimilar points have a label of -1
      return (
          np.vstack(
              [
                  np.column_stack([sim[:, 0], sim[:, 1]]),
                  np.column_stack([dis[:, 0], dis[:, 1]]),
              ]
          ),
          np.concatenate([np.ones(len(sim)), -np.ones(len(sim))]),
      )
  
imports: from sklearn.manifold import TSNE
  import metric_learn
  import numpy
  from sklearn.datasets import make_classification, make_regression
  import matplotlib.pyplot
label_desc: Use image node_id 2 for calling a global function with example usage: create_constraints(labels) and returns: np,  np