I have a list of dictionaries, with keys 'a', 'n', 'o', 'u'. Is there a way to speed up this calculation, for instance with NumPy? There are tens of thousands of items in the list.
The data is drawn from a database, so I must live with that it's in the form of a list of dictionaries originally.
x = n = o = u = 0 for entry in indata: x += (entry['a']) * entry['n'] # n - number of data points n += entry['n'] o += entry['o'] u += entry['u'] loops += 1 average = int(round(x / n)), n, o, u