Python Online Compiler
Example: Multiplication of Two Matrix in Python of Same Dimensions using For loop
C
C++
C#
Java
Python
PHP
main.py
STDIN
Run
# Multiplication of Two Matrix in Python of Same Dimensions using For loop x, y, m, r, c, i, j, k = [], [], [], 0, 0, 0, 0, 0 # r - Value of the number of rows # c - Value of the number of columns print ("Enter the number of rows & columns of the matrix::") r = int (input ()) c = int (input ()) # x - To store first matrix elements # y - To store second matrix elements # m - To store multiplication of matrices print ("\n---Enter the first matrix's elements---") for i in range (r): x.append([]) for j in range (c): x[i].append(int (input ())) print ("\n---Enter the second matrix's elements---") for i in range (r): y.append([]) for j in range (c): y[i].append(int (input ())) print ("\n-----The multiplication of the matrices is-----\n") # It's the calculation of matrices' multiplications for i in range (r): m.append([]) for j in range (c): m[i].append(0) for k in range (c): m[i][j] += x[i][k] * y[k][j] # This will display matrices's outputs for i in range (r): print ("\t") for j in range (c): print (m[i][j], end="\t") print ("\t", end="\t")
4 3 32 54 65 45 54 65 45 32 65 45 32 54 54 24 76 90 24 76 90 54 76 90 54 24
Output
Clear
ADVERTISEMENTS