Snippets

cia_rana 実対称行列の逆行列のベンチマーク

Created by cia_rana last modified
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)

Comments (0)

HTTPS SSH

You can clone a snippet to your computer for local editing. Learn more.