Created
May 29, 2017 18:58
-
-
Save cia-rana/ff87cd3d87a301957f08504271c5ecff to your computer and use it in GitHub Desktop.
実対称行列の逆行列のベンチマーク
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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