Skip to content

Commit ccc3a5b

Browse files
python3
1 parent 6e86af8 commit ccc3a5b

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed

numpy_class/python3/dot_for.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# https://deeplearningcourses.com/c/deep-learning-prerequisites-the-numpy-stack-in-python
2+
# https://www.udemy.com/deep-learning-prerequisites-the-numpy-stack-in-python
3+
4+
from __future__ import print_function, division
5+
from builtins import range
6+
# Note: you may need to update your version of future
7+
# sudo pip install -U future
8+
9+
10+
import numpy as np
11+
from datetime import datetime
12+
13+
a = np.random.randn(100)
14+
b = np.random.randn(100)
15+
T = 100000
16+
17+
def slow_dot_product(a, b):
18+
result = 0
19+
for e, f in zip(a, b):
20+
result += e*f
21+
return result
22+
23+
t0 = datetime.now()
24+
for t in range(T):
25+
slow_dot_product(a, b)
26+
dt1 = datetime.now() - t0
27+
28+
t0 = datetime.now()
29+
for t in range(T):
30+
a.dot(b)
31+
dt2 = datetime.now() - t0
32+
33+
print("dt1 / dt2:", dt1.total_seconds() / dt2.total_seconds())

0 commit comments

Comments
 (0)