Mean-Variance-STD Calculator error

hi all!

i wrote out the code for the mvstd calculator and i’m getting two errors returned to me from the unittest. both are ‘unsupported operand type(s) for -: ‘dict’ and ‘dict’’. i’ve tried to google to get some understanding but to no avail.

here’s the code:


import numpy as np

def calculate(list):
  calculations = {
  'mean': [],
  'variance': [],
  'standard deviation': [],
  'max': [],
  'min': [],
  'sum': []}

  if len(list) != 9:
    raise ValueError('List must contain nine numbers.')
  else:
    matrix = (np.array(list, dtype=float).reshape((3,3)))

  # mean
  calculations['mean'].append(np.mean(matrix, axis=0, dtype=float).tolist())
  calculations['mean'].append(np.mean(matrix, axis=1, dtype=float).tolist())
  calculations['mean'].append(np.mean(list).tolist())

  # variance
  calculations['variance'].append(np.var(matrix, axis=0, dtype=float).tolist())
  calculations['variance'].append(np.var(matrix, axis=1, dtype=float).tolist())
  calculations['variance'].append(np.mean(list).tolist())

  # standard deviation
  calculations['standard deviation'].append(np.std(matrix, axis=0, dtype=float).tolist())
  calculations['standard deviation'].append(np.std(matrix, axis=1, dtype=float).tolist())
  calculations['standard deviation'].append(np.std(list).tolist())
  
  # max
  calculations['max'].append(np.max(matrix, axis=0).tolist())
  calculations['max'].append(np.max(matrix, axis=1).tolist())
  calculations['max'].append(np.max(list).tolist())

  # min
  calculations['min'].append(np.min(matrix, axis=0).tolist())
  calculations['min'].append(np.min(matrix, axis=1).tolist())
  calculations['min'].append(np.min(list).tolist())
  
  # sum
  calculations['sum'].append(np.sum(matrix, axis=0, dtype=int).tolist())
  calculations['sum'].append(np.sum(matrix, axis=1, dtype=int).tolist())
  calculations['sum'].append(np.sum(list).tolist())

  return calculations

print(calculate([9,1,5,3,3,3,2,9,0]))

thanks!

Welcome to the forums, @jon.cokl .

The third one is not like the others.

oh my god.

…thank you so much. ahaha.

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