#!/usr/bin/env python3
#
# day1-ex1.py - weighted mean and error of uncorrelated measurements
import math

Rs =     [  0.5, 0.2, 0.3 ]
sigmas = [ 0.25, 0.1, 0.1 ]

def calc_weighted_mean_and_err(xs, sigmas):
    sum_x = 0
    sum_1 = 0
    for xi, sigmai in zip(xs, sigmas):
        w = 1 / (sigmai * sigmai)
        sum_x += w * xi
        sum_1 += w

    return sum_x / sum_1, math.sqrt(1 / sum_1)
 

print("weighted mean of {} measurements is {} +/- {}".format(
        len(Rs), *calc_weighted_mean_and_err(Rs, sigmas)))
