code: def cosine_distances(X, Y=None):
      """Compute cosine distance between samples in X and Y.
  
      Cosine distance is defined as 1.0 minus the cosine similarity.
  
      Read more in the :ref:`User Guide <metrics>`.
  
      Parameters
      ----------
      X : array_like, sparse matrix
          with shape (n_samples_X, n_features).
  
      Y : array_like, sparse matrix (optional)
          with shape (n_samples_Y, n_features).
  
      Returns
      -------
      distance matrix : array
          An array with shape (n_samples_X, n_samples_Y).
  
      See also
      --------
      sklearn.metrics.pairwise.cosine_similarity
      scipy.spatial.distance.cosine (dense matrices only)
      """
      # 1.0 - cosine_similarity(X, Y) without copy
      S = cosine_similarity(X, Y)
      S *= -1
      S += 1
      np.clip(S, 0, 2, out=S)
      if X is Y or Y is None:
          # Ensure that distances between vectors and themselves are set to 0.0.
          # This may not be the case due to floating point rounding errors.
          S[np.diag_indices_from(S)] = 0.0
      return S
  
imports: import itertools
  import numpy
  from scipy.spatial import distance
  from scipy.sparse import csr_matrix
  from scipy.sparse import issparse
  from ..utils import check_array
  from ..utils import gen_even_slices
  from ..utils import gen_batches
  from ..utils.fixes import partial
  from ..utils.extmath import row_norms, safe_sparse_dot
  from ..preprocessing import normalize
  from ..externals.joblib import Parallel
  from ..externals.joblib import delayed
  from ..externals.joblib import cpu_count
  from .pairwise_fast import _chi2_kernel_fast, _sparse_manhattan
label_desc: Use image node_id 8 for calling a global function with example usage: cosine_distances(X, Y) and returns: S