Jan-25-2022, 05:35 AM
Basically I am testing the 1st sample code in URL https://www.geeksforgeeks.org/vectorization-in-python/
When I run the code as it is it is (array size is 100000), the result looks good - same as the output in the webpage.
But when I increase the array size to be 100000000 (100millions), I noticed the classic computation and numpy.dot result is different.
My environment:
OS: MacOS 11.6.2
Python: 3.8.9
The code:
dot_product = 8.33333323333355e+23
Classic Computation time = 22549.694999999996ms
n_dot_product = 1659803504355747200
Vec Computation time = 131.33700000000204ms
I don't know why dot_product and n_dot_product are different. When I tried the code with N=100000, the dot_product and n_dot_product are same.
Thanks in advance.
When I run the code as it is it is (array size is 100000), the result looks good - same as the output in the webpage.
But when I increase the array size to be 100000000 (100millions), I noticed the classic computation and numpy.dot result is different.
My environment:
OS: MacOS 11.6.2
Python: 3.8.9
The code:
# Dot product import time import numpy import array # 8 bytes size int a = array.array('q') N=100000000 for i in range(N): a.append(i); b = array.array('q') for i in range(N, 2*N): b.append(i) # classic dot product of vectors implementation tic = time.process_time() dot = 0.0; for i in range(len(a)): dot += a[i] * b[i] toc = time.process_time() print("dot_product = "+ str(dot)); print("Classic Computation time = " + str(1000*(toc - tic )) + "ms") n_tic = time.process_time() n_dot_product = numpy.dot(a, b) n_toc = time.process_time() print("\nn_dot_product = "+str(n_dot_product)) print("Vec Computation time = "+str(1000*(n_toc - n_tic ))+"ms")The result is:
dot_product = 8.33333323333355e+23
Classic Computation time = 22549.694999999996ms
n_dot_product = 1659803504355747200
Vec Computation time = 131.33700000000204ms
I don't know why dot_product and n_dot_product are different. When I tried the code with N=100000, the dot_product and n_dot_product are same.
Thanks in advance.