![]() ![]() The order of the resultant Matrix will be m x lĮxample: # m x n * n x l : Gives m x l # 2 x 3 * 3 x 2 : Gives 2 x 2 # 2 x 3 * 4 x 2 : Cannot mutliply In the first matrix is equal to the number of rows in the other matrix.īasically: A m x n Matrix can only be multiplied with a n x l Matrix multiplication can only be implemented if the number of columns We can add and subract matrices extremely easily: matrix_list2 =, , ] matrix2 = Matrix ( 3, 3, matrix_list2 ) matrix3 = matrix1 + matrix2 print ( matrix3 ) #Prints: # Īdding an int / float to a matrix will perform the operation on allĮlements of the matrix and return a new matrix matrix4 = matrix1 + 5 print ( matrix4 ) #Prints: # Same way, print ( matrix4 - matrix1 ) # print ( matrix1 - 3 ) #Prints: # Multiplication and Division We can use a nested list to represent a Matrix during initialization ofĪn object In a nested list, the length of the outer list would be ‘m’Īnd the number of elements the inner lists have would be ‘n’ from matrix import Matrix matrix_list =, , ] matrix1 = Matrix ( 3, 3, matrix_list ) print ( matrix1 ) #Prints: # Operations on Matrices Addition and Subraction To create a matrix, specify the order of the Matrix (mxn) where theįirst argument (m) is the number of rows in the matrix and the second Addition, Multiplication, Division, Subraction operations supportedīetween matrices and between a matrix and a int / floatĬofactor of a given element in the Matrix
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |