Find combined mean and variance of two series | Function to find mean of series . ; Function to find the standard deviation of series . ; Function to find combined variance of two different series . ; mean1 and mean2 are the mean of two arrays . ; sd1 and sd2 are the standard deviation of two array . ; combinedMean is variable to store the combined mean of both array . ; d1_square and d2_square are the combined mean deviation . ; combinedVar is variable to store combined variance of both array . ; Driver Code ; Function call to combined mean .
def mean ( arr , n ) : NEW_LINE INDENT sum = 0 ; NEW_LINE for i in range ( n ) : NEW_LINE INDENT sum = sum + arr [ i ] ; NEW_LINE DEDENT mean = sum / n ; NEW_LINE return mean ; NEW_LINE DEDENT def sd ( arr , n ) : NEW_LINE INDENT sum = 0 ; NEW_LINE for i in range ( n ) : NEW_LINE INDENT sum = sum + ( ( arr [ i ] - mean ( arr , n ) ) * ( arr [ i ] - mean ( arr , n ) ) ) ; NEW_LINE DEDENT sdd = sum / n ; NEW_LINE return sdd ; NEW_LINE DEDENT def combinedVariance ( arr1 , arr2 , n , m ) : NEW_LINE INDENT mean1 = mean ( arr1 , n ) ; NEW_LINE mean2 = mean ( arr2 , m ) ; NEW_LINE print ( " Mean1 : ▁ " , round ( mean1 , 2 ) , " ▁ mean2 : ▁ " , round ( mean2 , 2 ) ) ; NEW_LINE sd1 = sd ( arr1 , n ) ; NEW_LINE sd2 = sd ( arr2 , m ) ; NEW_LINE print ( " StandardDeviation1 : ▁ " , round ( sd1 , 2 ) , " ▁ StandardDeviation2 : ▁ " , round ( sd2 , 2 ) ) ; NEW_LINE combinedMean = ( n * mean1 + m * mean2 ) / ( n + m ) ; NEW_LINE print ( " Combined ▁ Mean : ▁ " , round ( combinedMean , 2 ) ) ; NEW_LINE d1_square = ( ( mean1 - combinedMean ) * ( mean1 - combinedMean ) ) ; NEW_LINE d2_square = ( ( mean2 - combinedMean ) * ( mean2 - combinedMean ) ) ; NEW_LINE print ( " d1 ▁ square : ▁ " , round ( d1_square , 2 ) , " ▁ d2 _ square : ▁ " , round ( d2_square , 2 ) ) ; NEW_LINE combinedVar = ( n * ( sd1 + d1_square ) + m * ( sd2 + d2_square ) ) / ( n + m ) ; NEW_LINE print ( " Combined ▁ Variance : ▁ " , round ( combinedVar , 2 ) ) ; NEW_LINE DEDENT arr1 = [ 23 , 45 , 34 , 78 , 12 , 76 , 34 ] ; NEW_LINE arr2 = [ 65 , 67 , 34 , 23 , 45 ] ; NEW_LINE n = len ( arr1 ) ; NEW_LINE m = len ( arr2 ) ; NEW_LINE combinedVariance ( arr1 , arr2 , n , m ) ; NEW_LINE