Mean-variance-standart deviation calculator

I am facing a problem with this project. Does anyone can help me?

Here is my code

import numpy as np


def calculate(lst):
  calculations = {}
  if len(lst) != 9:
    raise ValueError('List must contain nine numbers.')
  else:

    ls = np.array(lst).reshape(3, 3)

    calculations['mean'] = [
      np.mean(ls, 0).tolist(),
      np.mean(ls, 1).tolist(),
      np.mean(ls)
    ]
    calculations['variance'] = [
      np.var(ls, 0).tolist(),
      np.var(ls, 1).tolist(),
      np.var(ls)
    ]
    calculations['standard deviation'] = [
      np.std(ls, 0).tolist(),
      np.std(ls, 1).tolist(),
      np.std(ls)
    ]
    calculations['max'] = [
      np.amax(ls, 0).tolist(),
      np.amax(ls, 1).tolist(),
      np.amax(ls)
    ]
    calculations['min'] = [
      np.amin(ls, 0).tolist(),
      np.amin(ls, 1).tolist(),
      np.amin(ls)
    ]
    calculations['sum'] = [
      np.sum(ls, 0).tolist(),
      np.sum(ls, 1).tolist(),
      np.sum(ls)
    ]
    return calculations

here is the error i am getting

  File "/nix/store/hd4cc9rh83j291r5539hkf6qd8lgiikb-python3-3.10.8/lib/python3.10/unittest/case.py", line 876, in assertAlmostEqual
    diff = abs(first - second)
TypeError: unsupported operand type(s) for -: 'dict' and 'dict'

Thank you

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.