Mean Variance Standard Deviation Calculator | FreeCodeCamp

preview_player
Показать описание
In this video, I go through how I did the mean variance standard deviation calculator project on freecodecamp. It is part of the Data Analysis with Python Certification. I learned a little bit about numpy from this project. If you learned something, let me know what you learned! Thanks for watching and have a great day!
Рекомендации по теме
Комментарии
Автор

These videos are the best man! Thank you!

anthonyaguilar
Автор

Another way to do this is to use np.mean(axis=0 or axis 1) and so on. But just remember to reshape the list into a matrix first. And add tolist() to change the array to list format in the end.

sukasuka
Автор

Thank you for a great video- solution plus explanation :)

arulvelan
Автор

I had to subscribe this is the best channel
Thanks a million

omareboaz
Автор

I believe the test wasn't that simple and the purpose of the function is to automate the calculation. If we change the value in the list, this function won't work. The better way is to use np.mean(a, axis=0 or 1) to automatically calculate the value. Also we need to convert the list into 3x3 array so as to detect the axis.
Btw, thanks so much for your help ^^.

nguyenanhquang
Автор

Please help!
in "mean_rows" it says:
IndexError: too many indices for array: array is 1-dimensional, but 3 were indexed
How can I solve that?

florenciarossi
Автор

My problem is I can not understand the questions or how to solve them. Why do we need to grab columns? and why are the indices those numbers for the columns?

jacquetrahan
Автор

Thank you, for helping. it;s a great help.

marluto
Автор

I find the FCC directions to be purposefully vague.

I kept getting this error when submitting: TypeError: unsupported operand type(s) for -: 'NoneType' and 'dict'
Langdon, when watching your video, you reminded us at 3:01 that "actually, it wants mean COLUMNS first", despite np arrays being indexed by ROWS, then COLUMNS. Why does DCC do this? To be tricky. So I switched my axis1 with axis2, and the test passed, so thank you for the reminder.

Also, you are indexing specific indexes with ls[[0, 1, 2]]. Another way is to use the np indexing to specify range, which would be:

# Extract rows, columns
row1 = nlist[0, :] (which can be read as 'Row 0, Columns ALL.)
row2 = nlist[1, :]
row3 = nlist[2, :]
col1 = nlist[:, 0]
col2 = nlist[:, 1]
col3 = nlist[:, 2]

...which uses [R:R, C:C] to target a RANGE of indexes. [R-start:R-stop, C-start:C-stop] where the stops are exclusive.
Example: ls[1:2, 0:2] is ls Row Index 1 to (but not including) 2, and Column Index 0 to (but not including) 2.
Seems more tedious until you have an array with 100, 000 rows and columns.

Pack those rows and columns into axis1, axis2, flattened, then perform calculations and be sure to return them as LISTS to then be given to the DICT at the end.

Hope that helps someone.

tahmato
Автор

Their classes have been to simple for this to be a project, it doesnt balance out

chefernandez
Автор

at 1:48, in my code numpy is not getting identify. what to do

MihikaTumulu
Автор

This code keep frustrating my effort am someone help me please.... i have used Chatgpt yet am not getting what i want.

josephsimeon
Автор

Who do we grab 0, 3, 6 etc for the columns....I can't understand it

jqts
Автор

I log in to the repl and my readme is like 6 lines, what's up with that?

bluesdog
Автор

sh: 1: Use: not found iam getting this error can anyone help me

qoudrum
Автор

Mine gives error return outside function

chefernandez
Автор

import numpy as np

def calculate(list):


if len(list) < 9:
raise ValueError("List must contain nine numbers.")

myarray = np.array(list).reshape(3, 3)
print(myarray)
mean_r = np.mean(myarray, axis=0)
mean_c = np.mean(myarray, axis = 1)
mean_f = np.mean(myarray)

var_r = np.var(myarray, axis=0)
var_c = np.var(myarray, axis = 1)
var_f = np.var(myarray)

std_r = np.std(myarray, axis = 0)
std_c = np.std(myarray, axis = 1)
std_f = np.std(myarray)

max_r= np.max(myarray, axis = 0)
max_c = np.max(myarray, axis = 1)
max_f = np.max(myarray)

min_r = np.min(myarray, axis=0)
min_c = np.min(myarray, axis = 1)
min_f = np.min(myarray)

sum_r = np.sum(myarray, axis=0)
sum_c = np.sum(myarray, axis = 1)
sum_f = np.sum(myarray)

return{
'mean': [mean_r, mean_c, mean_f],
'variance': [var_r, var_c, var_f],
'standard deviation': [std_r, std_c, std_f],
'max': [max_r, max_c, max_f],
'min': [min_r, min_c, min_f],
'sum': [sum_r, sum_c, sum_f]
}


why this is not working

A_Srivastav