I am wondering if there is a Pythonic way to calculate the means and deviations of the counters?
For example, I have four counters that use the same keys:
a = Counter({1: 23, 2: 39, 3: 1}) b = Counter({1: 28, 2: 39, 3: 1}) c = Counter({1: 23, 2: 39, 3: 2}) d = Counter({1: 23, 2: 22, 3: 1})
My way to do this is:
each_key_val = {} for i in a.keys():
I could use the following code to find the average / variance for each key:
np.mean(each_key_val[i]) np.var(each_key_val[i])
Is there an easier way to calculate the average / variance for each key compared to my method?
source share