We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
defmatrix_mul(A,B):ROWS_A,COLS_A=len(A),len(A[0])ROWS_B,COLS_B=len(B),len(B[0])assertCOLS_A==ROWS_BCOMMON_D=ROWS_B# zeros for Rows-A x Cols-BM_TIMES=[]forrinrange(ROWS_A):M_TIMES.append([0]*COLS_B)# Loop over Rows-A, then Cols-B, then the common dimensionforrAinrange(ROWS_A):forcBinrange(COLS_B):fortinrange(COMMON_D):M_TIMES[rA][cB]+=A[rA][t]*B[t][cB]returnM_TIMESdefprint_matrix(M,skip_indexes=[]):ROWS,COLS=len(M),len(M[0])forrinrange(ROWS):forcinrange(COLS):ifskip_indexesandskip_indexes[r][c]:continueprint(M[r][c])#####A=[[-2,-9],[1,4]]B=AEXP=1000for_inrange(EXP-1):B=matrix_mul(B,A)# print(B)print_matrix(B)
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Linear Algebra Foundations #7 - The 1000th Power of a Matrix
You are viewing a single comment's thread. Return to all comments →