I am attempting to take the weighted average of a list of Decimal numbers using numpy.average; however, I am receiving a TypeError. For example, consider the following.
>>> from decimal import *
>>> import numpy
>>> s = '1.00000001'
>>> l = []
>>> l.append(Decimal(s))
>>> l.append(Decimal(s))
>>> numpy.average(l)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib64/python2.6/site-packages/numpy/lib/function_base.py", line 612
, in average
avg = a.mean(axis)
TypeError: unsupported operand type(s) for /: 'Decimal' and 'float'
How do I take the weighted average of a list of Decimal numbers without converting to a float and losing precision of the values using numpy?