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_indexes[r][c]:continueprint(M[r][c])#####A=[[1,1,0],[0,1,0],[0,0,1]]B=AEXP=100for_inrange(EXP-1):B=matrix_mul(B,A)# print(B)print_matrix(B,skip_indexes=[[False,False,True],[True,False,True],[True,False,False]])
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 #5 - The 100th Power of a Matrix
You are viewing a single comment's thread. Return to all comments →