-
Notifications
You must be signed in to change notification settings - Fork 91
/
Copy pathb1.py
32 lines (21 loc) · 794 Bytes
/
b1.py
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
30
31
32
# Code listing #11
""" Module B (b.py) - Implement functions provide some statistical methods """
# Note - this is version 1 of b, so called b1.py
import a1 as a
def rms(narray):
""" Return root mean square of array of numbers"""
return pow(sum(a.squares(narray)), 0.5)
def mean(array):
""" Return mean of an array of numbers """
return 1.0*sum(array)/len(array)
def variance(array):
""" Return variance of an array of numbers """
# Square of variation from mean
avg = mean(array)
array_d = [(x - avg) for x in array]
variance = sum(a.squares(array_d))
return variance
def standard_deviation(array):
""" Return standard deviation of an array of numbers """
# S.D is square root of variance
return pow(variance(array), 0.5)