I am searching for a fast implementation to multiply two vectors of decimal in Python. I tried to make two lists and then multiply them:
from decimal import Decimal, getcontext
getcontext().prec = 20
import cProfile
a = [Decimal(x) for x in range(1,10000)]
b = [Decimal(x) for x in range(1,10000)]
def multiply(a,b):
[x*y for x,y in zip(a,b)]
cProfile.run('multiply(a,b)')
and this takes around 0.224
seconds. However, if I try to do the same for numpy vectors:
import numpy as np
a = np.arange(1,10000)
b = np.arange(1,10000)
def multiply(a,b):
a*b
cProfile.run('multiply(a,b)')
It takes 0.000
second. Is there any alternative way to make a vector of decimal and multiply them in python?