![]() |
time multiplying matrices and vectors
<p>I wrote this algorithm that resolves matrix-vector product two ways:
Imagine i have a matrix A nxn and a vector X nx1</p> <p>1) inner-product: Y11 = A11*X11 + A12*X21 + .... + A1n*n1 and so on</p> <p>2) lineal combination: Y = Colum1mn*X1 + Column2*X2 and so on</p> <p>I did this because i wanted to compare who is the fastest way to multiply Matrix-Vector i tried with</p> <p>n=[10000,9000,8000,7000,6000,5000,4000,3000,2000,1500,1000,800,500,300,100]</p> <p>run the algorith 3 times and took the average value with every value of n and <a href="https://i.stack.imgur.com/ICght.png" rel="nofollow noreferrer">got this graph</a>, and i was right, inner-product is the fastest because of how is saved matrix in memory thats ok but i ran algorithm 3 times to graph the points and got that Time of N=7000 > time of N=8000 > time of N=9000. And i want to know why is this? i thought that it could be something like the computer will start calculating slowly but if i run the algorithm more times it will calculate faster. But i ran the algorithm 7 times after the first 3 (10 in total) and got about the same result (this time n=7000 time was about 130 sec not 150 but still is time 7000 > time 8000 > time 9000)</p> <p>This is the code i wrote</p> <pre><code>def Lineal_C(A,x,n): y=np.zeros(n) t = time.clock() for j in range(n): for i in range(n): y[i]=y[i]+A[i][j]*x[j][0] time_spent = time.clock() - t print ("%.10f sec" % (time_spent)+" n"+str(n)+" Lineal Combination ") def Inner_P(A,x,n): y=np.zeros(n) t = time.clock() for i in range(0,n): for j in range(n): y[i]=y[i]+A[i][j]*x[j][0] time_spent = time.clock() - t print ("%.10f sec" % (time_spent)+" n="+str(n)+" ------MatVectFila - Producto Interno--------") </code></pre> [url=https://stackoverflow.com/questions/59010326/time-multiplying-matrices-and-vectors]More...[/url] |
所有时间均为北京时间。现在的时间是 19:49。 |
Powered by vBulletin
版权所有 ©2000 - 2025,Jelsoft Enterprises Ltd.