forked from sumedha3111/Python-for-Beginners
- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMeanAndVariance.py
More file actions
Latest commit
29 lines (25 loc) · 724 Bytes
/
Copy pathMeanAndVariance.py
File metadata and controls
29 lines (25 loc) · 724 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
importnumpyasnp
lst= []
n=int(input("Enter the value on N: "))
foriinrange(0, n):
ele=int(input())
lst.append(ele)
x=np.array(lst)
print("\nOriginal array: ")
print(x)
r1=np.mean(x)
r2=np.average(x)
assertnp.allclose(r1, r2)
print("\nMean: ", r1)
r1=np.std(x)
r2=np.sqrt(np.mean((x-np.mean(x)) **2 ))
assertnp.allclose(r1, r2)
print("\nstd: ", 1)
r1=np.var(x)
r2=np.mean((x-np.mean(x)) **2 )
assertnp.allclose(r1, r2)
print("\nvariance: ", r1)
"""
Variance is the variability of model prediction for a given data point or a value which tells us spread of our data
The sample mean is simply the average of all the measurements in the sample.
"""