File tree Expand file tree Collapse file tree 1 file changed +33
-0
lines changed
Expand file tree Collapse file tree 1 file changed +33
-0
lines changed Original file line number Diff line number Diff line change 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 ())
You can’t perform that action at this time.
0 commit comments