Skip to content

Instantly share code, notes, and snippets.

@cia-rana
Created May 29, 2017 18:58
Show Gist options
  • Save cia-rana/ff87cd3d87a301957f08504271c5ecff to your computer and use it in GitHub Desktop.
Save cia-rana/ff87cd3d87a301957f08504271c5ecff to your computer and use it in GitHub Desktop.
実対称行列の逆行列のベンチマーク
import numpy as np
import time
time1 = 0.
time2 = 0.
for i in range(10000):
a = (np.random.rand(3,3)*2-1.0)*100
a += a.T
if a.shape[0] == a.shape[1] and np.linalg.matrix_rank(a) == a.shape[0]:
# with Builtin
start = time.clock()
np.linalg.inv(a)
end = time.clock()
time1 += end - start
# with 固有値分解
start = time.clock()
la, U = np.linalg.eig(a)
U.dot(np.diag(np.reciprocal(la)).dot(U.T))
end = time.clock()
time2 += end - start
print(time1)
print(time2)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment