code: def condensedDistance(
      dupes: Scores,
  ) -> tuple[
      dict[int, RecordID], numpy.typing.NDArray[numpy.float_], int
  ]:
      """
      Convert the pairwise list of distances in dupes to "condensed
      distance matrix" required by the hierarchical clustering
      algorithms. Also return a dictionary that maps the distance matrix
      to the record_ids.
  
      The formula for an index of the condensed matrix is
  
      index = {N choose 2}-{N-row choose 2} + (col-row-1)
            = N*(N-1)/2 - (N-row)*(N-row-1)/2 + col - row - 1
              ^^^^^^^^^   ^^^^^^^^^^^^^^^^^^^
            matrix_length       row_step
  
      where (row,col) is index of an uncondensed square N X N distance matrix.
  
      See http://docs.scipy.org/doc/scipy/reference/generated/scipy.spatial.distance.squareform.html
      """
  
      candidate_set = numpy.unique(dupes["pairs"])
  
      i_to_id = dict(enumerate(candidate_set))
  
      ids = candidate_set.searchsorted(dupes["pairs"])
      row = ids[:, 0]
      col = ids[:, 1]
  
      N = len(candidate_set)
  
      # alternate form thanks to wolfram alpa
      index = row * (2 * N - row - 3) // 2 + col - 1
  
      condensed_distances = numpy.ones(N * (N - 1) // 2, "f4")
      condensed_distances[index] = 1 - dupes["score"]
  
      return i_to_id, condensed_distances, N
  
imports: from __future__ import annotations
  import array
  import itertools
  import logging
  import tempfile
  from collections import defaultdict
  from typing import Generator, Iterable, Sequence, cast
  import numpy
  import numpy.typing
  import scipy.cluster.hierarchy
  from dedupe._typing import ArrayLinks, Clusters, RecordID, Scores, TupleLinks
label_desc: Use image node_id 4 for calling a global function with example usage: condensedDistance(dupes) and returns: i_to_id,  condensed_distances,  N