Skip to content

Instantly share code, notes, and snippets.

@entron
Last active June 7, 2020 10:12
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 entron/3ec3db4b771072bf47f4da911cac7a7e to your computer and use it in GitHub Desktop.
Save entron/3ec3db4b771072bf47f4da911cac7a7e to your computer and use it in GitHub Desktop.
Test numpy installation.
import numpy as np
import numpy.random as npr
import time
# --- Test 1
N = 100
n = 2000
A = npr.randn(n, n)
B = npr.randn(n, n)
t = time.time()
for i in range(N):
C = np.dot(A, B)
td = time.time() - t
print("dotted two (%d,%d) matrices in %0.1f ms" % (n, n, 1e3 * td / N))
# --- Test 2
N = 100
n = 10000
A = npr.randn(n)
B = npr.randn(n)
t = time.time()
for i in range(N):
C = np.dot(A, B)
td = time.time() - t
print("dotted two (%d) vectors in %0.2f us" % (n, 1e6 * td / N))
# --- Test 3
m, n = (2000, 2000)
A = npr.randn(m, n)
t = time.time()
[U, s, V] = np.linalg.svd(A, full_matrices=False)
td = time.time() - t
print("SVD of (%d,%d) matrix in %0.3f s" % (m, n, td))
# --- Test 4
n = 2000
A = npr.randn(n, n)
t = time.time()
w, v = np.linalg.eig(A)
td = time.time() - t
print("Eigendecomp of (%d,%d) matrix in %0.3f s" % (n, n, td))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment