ENEL2CM Applied Computer Methods Course Question 6 PYTHON comes with the built-in function mean for computing the unweig
Posted: Wed Apr 27, 2022 3:44 pm
ENEL2CM Applied Computer Methods Course Question 6 PYTHON comes with the built-in function mean for computing the unweighted arithmetic mean of real numbers. Let x = {x1, x2, ..., xn} be an array of n real numbers. Then mean(x) X In some problems that arise in mathematical statistics one has to compute the weighted arithmetic mean of numbers in the array x. The latter, abbreviated here as wam, is defined as follows: wam(x, w) = kul Ew. kul Here w = {W1, W2, ..., Wn} is the array of weights associated with variables x. The weights are all nonnegative with w1 + W2+ ... + Wn> 0. In this exercise, you are to write the PYTHON function y = wam(x, w) that takes the arrays of variables and weights and returns the weighted arithmetic mean as defined above. Add three error messages to terminate prematurely execution of this file in the case when: arrays x and ware of different lengths at least one number in the array w is negative sum of all weights is equal to zero.