In [1]:
import numpy as np
a = np.array([1,2,3,4])
print(a)


[1 2 3 4]

In [6]:
import time

a = np.random.rand(1000000)
b = np.random.rand(1000000)

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

print(c)
print("Vectorized version:" + 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)
print("for loop:"+ str(1000*(toc-tic)) + "ms")


249886.802205
Vectorized version:1.18112564087ms
249886.802205
for loop:529.140949249ms

In [3]:


In [ ]: