def _get_groupings(dist_matrix_header, dist_matrix, groups, within=True, suppress_symmetry_and_hollowness_check=False):
 if (not suppress_symmetry_and_hollowness_check):
  if (not is_symmetric_and_hollow(dist_matrix)):
   raise ValueError('The distance matrix must be symmetric and hollow.')
 result = []
 group_items = groups.items()
 for (i, (row_group, row_ids)) in enumerate(group_items):
  row_indices = _get_indices(dist_matrix_header, row_ids)
  if within:
   block = dist_matrix[row_indices][:, row_indices]
   size = len(row_indices)
   indices = []
   for i in range(size):
    for j in range(i, size):
     if (i != j):
      indices.append(block[i][j])
   if indices:
    result.append((row_group, row_group, indices))
  else:
   for j in range((i + 1), len(groups)):
    (col_group, col_ids) = group_items[j]
    col_indices = _get_indices(dist_matrix_header, col_ids)
    vals = dist_matrix[row_indices][:, col_indices]
    vals = map(None, vals.flat)
    if vals:
     result.append((row_group, col_group, vals))
 return result

def _get_groupings ( dist_matrix_header , dist_matrix , groups , within = True , suppress_symmetry_and_hollowness_check = False ) : if ( not suppress_symmetry_and_hollowness_check ) : if ( not is_symmetric_and_hollow ( dist_matrix ) ) : raise ValueError ( 'The distance matrix must be symmetric and hollow.' ) result = [ ] group_items = groups . items ( ) for ( i , ( row_group , row_ids ) ) in enumerate ( group_items ) : row_indices = _get_indices ( dist_matrix_header , row_ids ) if within : block = dist_matrix [ row_indices ] [ : , row_indices ] size = len ( row_indices ) indices = [ ] for i in range ( size ) : for j in range ( i , size ) : if ( i != j ) : indices . append ( block [ i ] [ j ] ) if indices : result . append ( ( row_group , row_group , indices ) ) else : for j in range ( ( i + 1 ) , len ( groups ) ) : ( col_group , col_ids ) = group_items [ j ] col_indices = _get_indices ( dist_matrix_header , col_ids ) vals = dist_matrix [ row_indices ] [ : , col_indices ] vals = map ( None , vals . flat ) if vals : result . append ( ( row_group , col_group , vals ) ) return result
returns a list of distance groupings .