vendredi 25 août 2017

Grouping numbers

Hi I have been using this code that puts 16 random number into 4 different groups, I tried to add an average function however for some reason it doesn't work anymore?

import numpy
import random
members, n_groups = 4, 4
participants=list(range(1,members+1))*n_groups
print participants 
random.shuffle(participants)

with open('myfile1.txt','w') as tf:
    for i in range(n_groups):
        group = participants[i*members:(i+1)*members]
        for participant in group:
            tf.write(str(participant)+' ')
        tf.write('\n')

with open('myfile1.txt','r') as tf:
    g = [map(int, line.split()) for line in tf.readlines()]
    print g 
    print numpy.mean(g, axis=1)

Can anyone help please ? :) Appreciate it!




Aucun commentaire:

Enregistrer un commentaire