Data Analysis with Python Projects - Mean-Variance-Standard Deviation Calculator

This is my code

import numpy as np

def calculate(list):
  
  if(len(list) !=9):
    raise ValueError("List must contain nine numbers")

  list= np.array(list).reshape((3,3))

  calculations = {}

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

In Jupyter notebook is working fine but in replit i am getting below mentioned rror messages:

nix error: building nix env: exit status 1
Output has been trimmed to the last 20 lines
       … from call site

         at /nix/store/4va5hjb3sdk8pnpn3dsnkdg65fw28jgv-nixpkgs-23.05-src/lib/trivial.nix:430:7:

          429|     { # TODO: Should we add call-time "type" checking like built in?
          430|       __functor = self: f;
             |       ^
          431|       __functionArgs = args;

       (stack trace truncated; use '--show-trace' to show the full trace)

       error: undefined variable 'get-pip'

       at /home/runner/boilerplate-mean-variance-standard-deviation-calculator-1/replit.nix:3:17:

            2|   deps = [
            3|     pkgs.python get-pip.py
             |                 ^
            4|     pkgs.python get-pip.py

Requirement already satisfied: numpy in ./.pythonlibs/lib/python3.10/site-packages (1.26.2)

I’ve forked a working environment and pasted your code in here: https://replit.com/@pkdvalis/bhartigangwani70-mvsdeviation-calculator#mean_var_std.py

You can fork this and continue working on it :+1:

1 Like

Now it is showing the result and its like 0 test in 0 sec as shown below. Can someone please help

{‘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]}


Ran 0 tests in 0.000s

OK

Please link to your new replit

1 Like

Thanks for your help!

1 Like

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