def euclidean_distances(X, Y=None, Y_norm_squared=None, squared=False, X_norm_squared=None):
 (X, Y) = check_pairwise_arrays(X, Y)
 if (X_norm_squared is not None):
  XX = check_array(X_norm_squared)
  if (XX.shape == (1, X.shape[0])):
   XX = XX.T
  elif (XX.shape != (X.shape[0], 1)):
   raise ValueError('Incompatible dimensions for X and X_norm_squared')
 else:
  XX = row_norms(X, squared=True)[:, np.newaxis]
 if (X is Y):
  YY = XX.T
 elif (Y_norm_squared is not None):
  YY = np.atleast_2d(Y_norm_squared)
  if (YY.shape != (1, Y.shape[0])):
   raise ValueError('Incompatible dimensions for Y and Y_norm_squared')
 else:
  YY = row_norms(Y, squared=True)[np.newaxis, :]
 distances = safe_sparse_dot(X, Y.T, dense_output=True)
 distances *= (-2)
 distances += XX
 distances += YY
 np.maximum(distances, 0, out=distances)
 if (X is Y):
  distances.flat[::(distances.shape[0] + 1)] = 0.0
 return (distances if squared else np.sqrt(distances, out=distances))

def euclidean_distances ( X , Y = None , Y_norm_squared = None , squared = False , X_norm_squared = None ) : ( X , Y ) = check_pairwise_arrays ( X , Y ) if ( X_norm_squared is not None ) : XX = check_array ( X_norm_squared ) if ( XX . shape == ( 1 , X . shape [ 0 ] ) ) : XX = XX . T elif ( XX . shape != ( X . shape [ 0 ] , 1 ) ) : raise ValueError ( 'Incompatible dimensions for X and X_norm_squared' ) else : XX = row_norms ( X , squared = True ) [ : , np . newaxis ] if ( X is Y ) : YY = XX . T elif ( Y_norm_squared is not None ) : YY = np . atleast_2d ( Y_norm_squared ) if ( YY . shape != ( 1 , Y . shape [ 0 ] ) ) : raise ValueError ( 'Incompatible dimensions for Y and Y_norm_squared' ) else : YY = row_norms ( Y , squared = True ) [ np . newaxis , : ] distances = safe_sparse_dot ( X , Y . T , dense_output = True ) distances *= ( - 2 ) distances += XX distances += YY np . maximum ( distances , 0 , out = distances ) if ( X is Y ) : distances . flat [ : : ( distances . shape [ 0 ] + 1 ) ] = 0.0 return ( distances if squared else np . sqrt ( distances , out = distances ) )
considering the rows of x as vectors .