samedi 18 juin 2016

How to remove minimum value from row in a matrix-

So our assinment is to create a function that take the input grades~(An N ×M matrix containing grades on the 7-step-scale given to N students on M different assignments.), and compute gradesFinal(A vector of length n containing the final grade for each of the N students.).

For each student, the final grade must be computed in the following way:

  1. If there is only one assignment (M = 1) the final grade is equal to the grade of that assignment.

  2. If there are two or more assignments (M > 1) the lowest grade is discarded. The final grade is computed as the mean of M − 1 highest grades rounded to the nearest grade on the scale (using the function roundGrade).

  3. Irrespective of the above, if a student has received the grade −3 in one or more assignments, the final grade must always be −3.

I have inserted my roundGrade function below, but when I try to run a matrix I recieve. "TypeError: unsupported operand type(s) for /: 'NoneType' and 'int'". This means I probably misunderstood something completely.

import numpy as np
def computeFinalGrades(grades):
    if len(grades)==1:
    gradesFinal = grades
elif len(grades)>=2:
    trimmed = grades.remove(min(grades))
    finalgrade = np.mean(trimmed)
    gradesFinal = roundGrade(finalgrade)
elif grades[grades==-3]:
    gradesFinal= -3
    return gradesFinal

def roundGrade(grades):
   grade_groups = [-3,0,2,4,7,10,12]
   gradesRounded = [min(grade_groups,key=lambda x:abs(grade-x)) for grade in     grades]
   return gradesRounded

I appreciate your help, and feel welcome to show me a smarter method.

Aucun commentaire:

Enregistrer un commentaire