0% found this document useful (0 votes)
3 views2 pages

Matrix Multiplication in Python Code

The document contains a Python script for matrix multiplication. It defines a function that checks if two matrices can be multiplied and performs the multiplication if possible. The script also includes example matrices and prints the result of the multiplication.

Uploaded by

23412047
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views2 pages

Matrix Multiplication in Python Code

The document contains a Python script for matrix multiplication. It defines a function that checks if two matrices can be multiplied and performs the multiplication if possible. The script also includes example matrices and prints the result of the multiplication.

Uploaded by

23412047
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

we malees.

Ipat
i a d mt Clmxp

mahB.

>Caat comptiy esnant mat

(evmmen

alomod
[Link] Save Run Shell Clear

0eT matrix_muLtipilcat1on(mat i, matz) : - result of matrix multiplication


2- 1f len (mati[0))-len(mat2): (94, 98)
print("matrices cannot be multiplied" ) (116, 119]
return None
result C[O for _ in range(len (mat2[0] ) )] for in range( len(mat1 ))]
6 for 1 in range (1en(mat 1 ) )
7 for 1 in range (len (mat 2[0) ):
8 for k Ln range (len(mat2) ):
result[1)J[j]" -mat 1[1] [k] *mat2[k] [J)
10 return result
11- matrix1
17 [2,5,7].
13 (5,8,6].
14 1
15- matrix2 (
1 [4,5).
17 [6,51.
18 (8,9].
19
20 resultant_matrix-matr1ix_multiplicat ion (matrix1 ,matrix2)
21- 1f resultant_matr1x:
22 print("result of matrix multiplicarion")
23 for row in resultant_matrix :
nrinr(row)

You might also like