forked from lazyprogrammer/machine_learning_examples
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdot_for.py
More file actions
33 lines (25 loc) · 772 Bytes
/
dot_for.py
File metadata and controls
33 lines (25 loc) · 772 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# https://deeplearningcourses.com/c/deep-learning-prerequisites-the-numpy-stack-in-python
# https://www.udemy.com/deep-learning-prerequisites-the-numpy-stack-in-python
from __future__ import print_function, division
from builtins import range
# Note: you may need to update your version of future
# sudo pip install -U future
import numpy as np
from datetime import datetime
a = np.random.randn(100)
b = np.random.randn(100)
T = 100000
def slow_dot_product(a, b):
result = 0
for e, f in zip(a, b):
result += e*f
return result
t0 = datetime.now()
for t in range(T):
slow_dot_product(a, b)
dt1 = datetime.now() - t0
t0 = datetime.now()
for t in range(T):
a.dot(b)
dt2 = datetime.now() - t0
print("dt1 / dt2:", dt1.total_seconds() / dt2.total_seconds())