I m watching the video of Vectorization in that author explain vectorization will reduce the time for computation. For example
Code:
import numpy as np
import time
a= np.random.rand(100000)
b= np.random.rand(100000)
tic = time.time()
c = np.dot(a,b)
toc = time.time()
print(c)
print("Vectorization Version: "+ str(100000 * (toc - tic)) +"ms" )
c = 0
tic = time.time()
for i in range(100000):
c += a[i] * b[i]
toc = time.time()
print(c)
print("NonVectorization Version: "+ str(100000 * (toc - tic)) +"ms" )
Output:
25108.8250776
Vectorization Version: 12.660026550292969ms
25108.8250776
NonVectorization Version: 7782.268524169922ms
How vectorization are helpful in reducing the computation time?