Skip to content

Instantly share code, notes, and snippets.

@Robofied
Created February 12, 2019 16:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Robofied/67951bdb24ef5884f7976670cc3ac3ac to your computer and use it in GitHub Desktop.
Save Robofied/67951bdb24ef5884f7976670cc3ac3ac to your computer and use it in GitHub Desktop.
Numpy Library
#Import Numpy in Python
import numpy as np
a = np.random.rand(5,1)
print(a)
#[Output]:
#[[0.28642857]
# [0.51330181]
# [0.92992345]
# [0.27376296]
# [0.21996422]]
## Show how much time vectorized version take for calculation
import time
a = np.random.rand(1000000)
b = np.random.rand(1000000)
tic = time.time()
c = np.dot(a,b)
toc = time.time()
print("Vectorized Version " + str(1000*(toc-tic)) + "ms")
#[Output]:
#Vectorized Version 0.0ms
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment