In [32]:
import numpy as np
import time

In [33]:
x1 = [9, 2, 5, 0, 0, 7, 5, 0, 0, 0, 9, 2, 5, 0, 0]
x2 = [9, 2, 2, 9, 0, 9, 2, 5, 0, 0, 9, 2, 5, 0, 0]

### VECTORIZED DOT PRODUCT OF VECTORS ###

tic = time.process_time()
dot = np.dot(x1,x2)
toc = time.process_time()
print ("Dot Vectors = " + str(dot) + "\nComputation time = " + str(1000*(toc - tic)) + "ms")


Dot Vectors = 278
Computation time = 1.55100000000008ms

In [34]:
### VECTORIZED OUTER PRODUCT ###

tic = time.process_time()
outer = np.outer(x1,x2)
toc = time.process_time()
print ("###############> Outer Product <###############>\t\n"
       +str(outer)+ "\n\nComputation time = " + str(1000*(toc - tic)) + "ms")


###############> Outer Product <###############>	
[[81 18 18 81  0 81 18 45  0  0 81 18 45  0  0]
 [18  4  4 18  0 18  4 10  0  0 18  4 10  0  0]
 [45 10 10 45  0 45 10 25  0  0 45 10 25  0  0]
 [ 0  0  0  0  0  0  0  0  0  0  0  0  0  0  0]
 [ 0  0  0  0  0  0  0  0  0  0  0  0  0  0  0]
 [63 14 14 63  0 63 14 35  0  0 63 14 35  0  0]
 [45 10 10 45  0 45 10 25  0  0 45 10 25  0  0]
 [ 0  0  0  0  0  0  0  0  0  0  0  0  0  0  0]
 [ 0  0  0  0  0  0  0  0  0  0  0  0  0  0  0]
 [ 0  0  0  0  0  0  0  0  0  0  0  0  0  0  0]
 [81 18 18 81  0 81 18 45  0  0 81 18 45  0  0]
 [18  4  4 18  0 18  4 10  0  0 18  4 10  0  0]
 [45 10 10 45  0 45 10 25  0  0 45 10 25  0  0]
 [ 0  0  0  0  0  0  0  0  0  0  0  0  0  0  0]
 [ 0  0  0  0  0  0  0  0  0  0  0  0  0  0  0]]

Computation time = 0.5379999999999274ms

In [35]:
### VECTORIZED ELEMENTWISE MULTIPLICATION ###

tic = time.process_time()
mul = np.multiply(x1,x2)
toc = time.process_time()
print ("Elementwise Multiplication = " + str(mul) + "\nComputation time = "+str(1000*(toc - tic))+"ms")


Elementwise Multiplication = [81  4 10  0  0 63 10  0  0  0 81  4 25  0  0]
Computation time = 0.09999999999998899ms

In [36]:
### VECTORIZED GENERAL DOT PRODUCT ###
tic = time.process_time()
dot = np.dot(x1,x2)
toc = time.process_time()
print ("gdot = " + str(dot) + "\n ----- Computation time = " + str(1000*(toc - tic)) + "ms")


gdot = 278
 ----- Computation time = 0.10299999999996423ms

In [ ]: