Simple Statistics on Arrays Damian Gordon Minimum Value

  • Slides: 10
Download presentation
Simple Statistics on Arrays Damian Gordon

Simple Statistics on Arrays Damian Gordon

Minimum Value in Array • So let’s say we want to express the following

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

# PROGRAM Min. Val: Age = [44, 23, 42, 33, 18, 54, 34, 16]

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

Maximum Value in Array • So let’s say we want to express the following

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

# PROGRAM Max. Val: Age = [44, 23, 42, 33, 18, 54, 34, 16]

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

Average Value in Array • So let’s say we want to express the following

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

# PROGRAM Avg. Val: Age = [44, 23, 42, 33, 18, 54, 34, 16]

# PROGRAM Avg. Val: 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.

Standard Deviation of Array • So let’s say we want to express the following

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

# PROGRAM Std. Dev. Val: import math #### Calculate Average ### Age = [44,

# PROGRAM Std. Dev. Val: import math #### Calculate Average ### Age = [44, 23, 42, 33, 18, 54, 34, 16] Total. Avg = 0 for index in range(0, len(Age)): # DO Total. Avg = Total. Avg + Age[index] # ENDFOR; Average. Val = Total. Avg/len(Age) #### Calculate Standard Deviation ### Total. Std. Dev. Num = 0 for index in range(0, len(Age)): # DO Std. Dev. Num = (Age[index] - Average. Val) * (Age[index] - Average. Val) Total. Std. Dev. Num = Total. Std. Dev. Num + Std. Dev. Num # ENDFOR; print(math. sqrt(Total. Std. Dev. Num/len(Age)-1)) # END.

etc.

etc.