vendredi 25 août 2017

Creating a rating system for randomised groups

So I have this code that groups (1,2,3,4)(x4) into 4 groups, I was trying find a way to rate these groups. E.G. (1,1,1,1) is a good group since there are no other numbers (1,2,3,4) would be the worst group. So does anyone know a way to check the number of different values in a group e.g. (1111) have 1 value, where as (1,2,3,3) has 3 changes.

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 = [list(map(int, line.split())) for line in tf.readlines()]
    print(g)
    print(numpy.mean(g, axis=1))




Aucun commentaire:

Enregistrer un commentaire