In [4]:
import numpy as np
import time

In [24]:
a = np.random.rand(1000000)
b = np.random.rand(1000000)

c = 0
tic = time.time()
c = np.dot(a, b)
toc = time.time()

print("c: ", c)
print("Vectorized: " + str(1000 * (toc - tic)) + " ms")

c = 0
tic = time.time()
for i in range(1000000):
    c += a[i] * b[i]
toc = time.time()

print("c: ", c)
print("For loop: " + str(1000 * (toc - tic)) + " ms")


c:  250312.386785
Vectorized: 1.003265380859375 ms
c:  250312.386785
For loop: 416.1062240600586 ms

In [ ]:


In [ ]: