def dist_matrix_linkage(matrix, linkage=AVERAGE):
 distances = condensedform(matrix)
 if ((linkage == WARD) and (not _HAS_WARD_LINKAGE_FROM_DIST)):
  y = numpy.asarray(distances, dtype=float)
  scipy.spatial.distance.is_valid_y(y, throw=True)
  N = scipy.spatial.distance.num_obs_y(y)
  Z = numpy.zeros(((N - 1), 4))
  method = scipy.cluster.hierarchy._cpy_euclid_methods['ward']
  scipy.cluster.hierarchy._hierarchy.linkage(y, Z, int(N), int(method))
  return Z
 else:
  return scipy.cluster.hierarchy.linkage(distances, method=linkage)

def dist_matrix_linkage ( matrix , linkage = AVERAGE ) : distances = condensedform ( matrix ) if ( ( linkage == WARD ) and ( not _HAS_WARD_LINKAGE_FROM_DIST ) ) : y = numpy . asarray ( distances , dtype = float ) scipy . spatial . distance . is_valid_y ( y , throw = True ) N = scipy . spatial . distance . num_obs_y ( y ) Z = numpy . zeros ( ( ( N - 1 ) , 4 ) ) method = scipy . cluster . hierarchy . _cpy_euclid_methods [ 'ward' ] scipy . cluster . hierarchy . _hierarchy . linkage ( y , Z , int ( N ) , int ( method ) ) return Z else : return scipy . cluster . hierarchy . linkage ( distances , method = linkage )
return linkage using a precomputed distance matrix .