Presentation is loading. Please wait.

Presentation is loading. Please wait.

Simple Statistics on Arrays

Similar presentations


Presentation on theme: "Simple Statistics on Arrays"— Presentation transcript:

1 Simple Statistics on Arrays
Damian Gordon

2 Minimum Value in Array So let’s say we want to express the following algorithm: Find the minimum value in an array

3 # PROGRAM MinVal: Age = [44, 23, 42, 33, 18, 54, 34, 16] MinVal = Age[0] for index in range(0,len(Age)): # DO if MinVal > Age[index]: # THEN MinVal = Age[index] # ENDIF; # ENDFOR; print(MinVal) # END.

4 Maximum Value in Array So let’s say we want to express the following algorithm: Find the maximum value in an array

5 # PROGRAM MaxVal: Age = [44, 23, 42, 33, 18, 54, 34, 16] MaxVal = Age[0] for index in range(0,len(Age)): # DO if MaxVal < Age[index]: # THEN MaxVal = Age[index] # ENDIF; # ENDFOR; print(MaxVal) # END.

6 Average Value in Array So let’s say we want to express the following algorithm: Find the average value of an array

7 # PROGRAM AvgVal: Age = [44, 23, 42, 33, 18, 54, 34, 16] Total = 0 for index in range(0,len(Age)): # DO Total = Total + Age[index] # ENDFOR; print(Total/len(Age)) # END.

8 Standard Deviation of Array
So let’s say we want to express the following algorithm: Find the standard deviation of an array

9 # PROGRAM StdDevVal: import math #### Calculate Average ### Age = [44, 23, 42, 33, 18, 54, 34, 16] TotalAvg = 0 for index in range(0,len(Age)): # DO TotalAvg = TotalAvg + Age[index] # ENDFOR; AverageVal = TotalAvg/len(Age) #### Calculate Standard Deviation ### TotalStdDevNum = 0 StdDevNum = (Age[index] - AverageVal) * (Age[index] - AverageVal) TotalStdDevNum = TotalStdDevNum + StdDevNum print(math.sqrt(TotalStdDevNum/len(Age)-1)) # END.

10 etc.


Download ppt "Simple Statistics on Arrays"

Similar presentations


Ads by Google