code: def dist_squared(X1, X2):
      """If X1 is n1xd and X2 is n2xd, this returns an n1xn2 matrix where the (i,j)th
      entry is the squared distance between X1(i,:) and X2(j,:).
      """
      n1, dim1 = X1.shape
      n2, dim2 = X2.shape
      if dim1 != dim2:
          raise ValueError(
              "Second dimension of X1 and X2 should be equal."
          )
      dist_sq = (
          np.outer(np.ones(n1), (X2**2).sum(axis=1))
          + np.outer((X1**2).sum(axis=1), np.ones(n2))
          - 2 * X1.dot(X2.T)
      )
      dist_sq = np.clip(dist_sq, 0.0, np.inf)
      return dist_sq
  
imports: from __future__ import print_function
  from __future__ import division
  import numpy
  from scipy.sparse import dok_matrix
  from scipy.linalg import solve_triangular
label_desc: Use image node_id 8 for calling a global function with example usage: dist_squared(X1, X2) and returns: dist_sq