docstr: transform.
  
  Transform X to a cluster-distance space.
  
  Arguments:
      X: `Array` or `list` of `Array`. The sample(s) to transform.
  
  Returns:
      `Array` of shape (n_clusters). The distance of X to each centroid.
docstr_tok: ["transform",".","Transform","X","to","a","cluster-distance","space",".","Arguments",":","X",":","`","Array","`","or","`","list","`","of","`","Array","`",".","The","sample","(","s",")","to","transform",".","Returns",":","`","Array","`","of","shape","(","n_clusters",")",".","The","distance","of","X","to","each","centroid","."]
code: def transform(self, X):
      """transform.
  
      Transform X to a cluster-distance space.
  
      Arguments:
          X: `Array` or `list` of `Array`. The sample(s) to transform.
  
      Returns:
          `Array` of shape (n_clusters). The distance of X to each centroid.
  
      """
  
      X, orig_ndim = prepare_X(
          X, 2, max_dim=2, min_dim=1, debug_msg="X"
      )
  
      with self.graph.as_default():
          # Build Tree Graph
          self._build_estimator()
          if not self._transform.is_ready:
              input = tf.placeholder(
                  tf.float32,
                  name="transform_input",
                  shape=[None, self.num_features],
              )
              centers = self._cluster_centers_vars
              centers = tf.reshape(
                  centers, shape=[self.n_clusters, self.num_features]
              )
  
              if self.distance == c_ops.SQUARED_EUCLIDEAN_DISTANCE:
                  dist_fn = euclidean
              elif self.distance == c_ops.COSINE_DISTANCE:
                  dist_fn = cosine
              else:
                  raise Exception("Incorrect distance metric.")
  
              output = tf.map_fn(
                  lambda x: tf.map_fn(lambda y: dist_fn(x, y), centers),
                  input,
              )
  
              self._build_transform(input, output)
          distances = self.session.run(
              self._transform.output_tensor,
              feed_dict={self._transform.input_tensor: X},
          )
          if orig_ndim == 1:
              distances = distances[0]
          return distances
  
imports: from __future__ import division, print_function, absolute_import
  from datetime import datetime
  import os
  import math
  import numpy
  import time
  import tensorflow.compat.v1
  from tensorflow.contrib.factorization.python.ops import clustering_ops
  from tensorflow.contrib.tensor_forest.python.ops import data_ops
  from tensorflow.python.ops import state_ops, array_ops, math_ops
  from ...utils import validate_dim, read_tensor_in_checkpoint, prepare_X
  from ...data_utils import get_num_features, get_num_sample
  from ...data_flow import generate_data_tensor
  from ...distances import euclidean, cosine
  from ..base import BaseEstimator
label_desc: Use image node_id 14 for calling the KMeansBase obj's underlying member method code with example usage: obj.transform(X) and returns: distances