def ave_seqs_per_sample(matrix, seqs_per_samp, sampleIDs):
 ave_ser = {}
 temp_dict = {}
 for (i, sid) in enumerate(sampleIDs):
  temp_dict[sid] = {}
  for (j, seq) in enumerate(seqs_per_samp):
   try:
    temp_dict[sid][seq].append(matrix[i][j])
   except KeyError:
    temp_dict[sid][seq] = []
    temp_dict[sid][seq].append(matrix[i][j])
 for sid in sampleIDs:
  ave_ser[sid] = []
  keys = sorted(temp_dict[sid].keys())
  for k in keys:
   ave_ser[sid].append(mean(array(temp_dict[sid][k]), 0))
 return ave_ser

def ave_seqs_per_sample ( matrix , seqs_per_samp , sampleIDs ) : ave_ser = { } temp_dict = { } for ( i , sid ) in enumerate ( sampleIDs ) : temp_dict [ sid ] = { } for ( j , seq ) in enumerate ( seqs_per_samp ) : try : temp_dict [ sid ] [ seq ] . append ( matrix [ i ] [ j ] ) except KeyError : temp_dict [ sid ] [ seq ] = [ ] temp_dict [ sid ] [ seq ] . append ( matrix [ i ] [ j ] ) for sid in sampleIDs : ave_ser [ sid ] = [ ] keys = sorted ( temp_dict [ sid ] . keys ( ) ) for k in keys : ave_ser [ sid ] . append ( mean ( array ( temp_dict [ sid ] [ k ] ) , 0 ) ) return ave_ser
calculate the average for each sampleid across each number of seqs/sample .