Python - Mean-Variance-Standard Deviation Calculator

Tell us what’s happening:
Could someone tell me why my code isn’t passing the test? I don’t understand the difference between my result and the expected result.

Regards!

Your code so far

def calculate(values):
    result = {}
    data = np.array(values)
    size = (3, 3)
    try:
        data = np.reshape(data, size)
    except:
        raise ValueError('List must contain nine numbers.')
    mean_0 = data.mean(axis=0).tolist()
    mean_1 = data.mean(axis=1).tolist()
    mean_total = data.mean()
    result['mean'] = mean_0, mean_1, mean_total

    variance = data.var()
    variance_0 = data.var(axis=0).tolist()
    variance_1 = data.var(axis=1).tolist()
    result['variance'] = variance_0, variance_1, variance

    std = data.std()
    std_0 = data.std(axis=0).tolist()
    std_1 = data.std(axis=1).tolist()
    result['standar deviation'] = std_0, std_1, std

    max_number = data.max()
    max_number_0 = data.max(axis=0).tolist()
    max_number_1 = data.max(axis=1).tolist()
    result['max'] = max_number_0, max_number_1, max_number

    min_number = data.min()
    min_number_0 = data.min(axis=0).tolist()
    min_number_1 = data.min(axis=1).tolist()
    result['min'] = min_number_0, min_number_1, min_number

    sum_data = data.sum()
    sum_data_0 = data.sum(axis=0).tolist()
    sum_data_1  = data.sum(axis=1).tolist()
    result['sum'] = sum_data_0, sum_data_1, sum_data
    # print(result)
    return result

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.111 Safari/537.36 OPR/72.0.3815.186.

Challenge: Mean-Variance-Standard Deviation Calculator

Link to the challenge:

It’s easier if you’ll post a link to a repl.it and test results too for debugging these kind of problems. I copied and ran your code and spotted two problems. One, there is a ‘d’ missing in ‘standard’ deviation. Two, you are outputting tuples instead of lists:

mine:

{'mean': [[3.0, 4.0, 5.0], [1.0, 4.0, 7.0], 4.0], 'variance': [[6.0, 6.0, 6.0], [0.6666666666666666, 0.6666666666666666, 0.6666666666666666], 6.666666666666667], 'standard deviation': [[2.449489742783178, 2.449489742783178, 2.449489742783178], [0.816496580927726, 0.816496580927726, 0.816496580927726], 2.581988897471611], 'max': [[6, 7, 8], [2, 5, 8], 8], 'min': [[0, 1, 2], [0, 3, 6], 0], 'sum': [[9, 12, 15], [3, 12, 21], 36]}

yours:

{'mean': ([3.0, 4.0, 5.0], [1.0, 4.0, 7.0], 4.0), 'variance': ([6.0, 6.0, 6.0], [0.6666666666666666, 0.6666666666666666, 0.6666666666666666], 6.666666666666667), 'standar deviation': ([2.449489742783178, 2.449489742783178, 2.449489742783178], [0.816496580927726, 0.816496580927726, 0.816496580927726], 2.581988897471611), 'max': ([6, 7, 8], [2, 5, 8], 8), 'min': ([0, 1, 2], [0, 3, 6], 0), 'sum': ([9, 12, 15], [3, 12, 21], 36)}

Since those are the only differences, your program should pass the tests once you fix them (it did for me).