matrix multiplication python

Solutions on MaxInterview for matrix multiplication python by the best coders in the world

showing results for - "matrix multiplication python"
Thiago
02 Jul 2016
1# Program to multiply two matrices using nested loops
2
3# 3x3 matrix
4X = [[12,7,3],
5    [4 ,5,6],
6    [7 ,8,9]]
7# 3x4 matrix
8Y = [[5,8,1,2],
9    [6,7,3,0],
10    [4,5,9,1]]
11# result is 3x4
12result = [[0,0,0,0],
13         [0,0,0,0],
14         [0,0,0,0]]
15
16# iterate through rows of X
17for i in range(len(X)):
18   # iterate through columns of Y
19   for j in range(len(Y[0])):
20       # iterate through rows of Y
21       for k in range(len(Y)):
22           result[i][j] += X[i][k] * Y[k][j]
23
24for r in result:
25   print(r)
26
Ousmane
14 Feb 2020
1# input two matrices of size n x m 
2matrix1 = [[12,7,3], 
3        [4 ,5,6], 
4        [7 ,8,9]] 
5matrix2 = [[5,8,1], 
6        [6,7,3], 
7        [4,5,9]] 
8  
9res = [[0 for x in range(3)] for y in range(3)]  
10  
11# explicit for loops 
12for i in range(len(matrix1)): 
13    for j in range(len(matrix2[0])): 
14        for k in range(len(matrix2)): 
15  
16            # resulted matrix 
17            res[i][j] += matrix1[i][k] * matrix2[k][j] 
18  
19print (res) 
20
Vincenzo
19 Jan 2017
1>>> a = np.array([[ 5, 1 ,3], 
2                  [ 1, 1 ,1], 
3                  [ 1, 2 ,1]])
4>>> b = np.array([1, 2, 3])
5>>> print a.dot(b)
6array([16, 6, 8])
queries leading to this page
matrix multiplication python numpypython code for matrix multiplicationmatrix matrix multiplication pythonmatrix multiplication program in pythonmultiplication of matrices in python 3how to multiply 2 matrices in python using numpymatrix multiplication python using numpymultiply to matrices in pythonpython multiply matrix matrix multiplication examplenumpy multiply matrixmatrices multiplication in pythonmatrix multi as np array for pythonmatrix multiplication list comprehension pythonmultiply matrices in pythonmultiplication of matrix in pythonnumpy multiply two arraysnumpy array multiplicationnumpy multiply matrixes 2cmatrix multiplicationhow to matrix multiply in numpyhow to matrix multiplication in pythonpython library matrix multiplicationhow to do matrix multiplication in numpypython program for matrix multiplicationhow to multiply to matrix in pythonmultiplication of matrix python write a python program to perform matrix multiplication multiplication pythonmatrix multiplication with numpynumpy matrix multiplication codematrix multiplication pymultiply matrix in pythonto write a python program to perform matrix multiplication numpy matrix vector multiplicationmatrix product in numpymatrix product numpypython multiplication matrixpython matrix multipicationmatrix vector product numpytwo matrix multiplication in pythonstrassen 27s matrix multiplication pymatrix multiplication python 40matrix multiplication pythonmultiplying matrices in pythonmultiply matrix pythonwrite a python program to perform matrix multiplicationhow to do matrix multiplication in pythonmatriz multiplication in pythonpython2 matrix multiplicationmatrix multiplication program pythonhow to matrix multiplication in nupymatrix multiplcation numpyarray multiplication in mumpyhow to do matrix multiplication numpymatrix mulptilication numynumpy python matrix multiplicationmatrix multiplication in python using numpymultiplication matrix pythonhow to multiply 2 arrays in python numpymatrix multiplication in python numpymatrix multipication numpymatrix multiplication in pythonhow to multiply array with matrix in pythonpython matrix multiplication atprogram for matrix multiplication pythonnumpy multiply n no of matrixnumber of multiplication in matrixhow to print directly matrix multiplication in pythonpython program for multiplication of matricesthree matrix multiplication pythonmultiply matrices pythonhow to multiply matrix in pythonpython matrix multiplication librarynumpy matrix multiplicationprogram for matrix multiplication in pythonmultiplication of two matrices in pythonpython numpy matrix multiplicationmatrix multiplication numpypython matrix multiplicationmatrix multiplication using pythonuse numpy for matrix multiplicationmultiplication of matrix numpymultiplication of matrixmatrix multiplication of two numpy arrayspython matrix multiplication numpyhow to code matrix multiplication in pythonmatrix multiplicationto write a python program to perform matrix multiplicationhow to multiply matrices pythonmatrix multiplication in numpypython multiply matricespython prg to multply matricesmatrix multiplication in python with numpypythonmatrix multiplicationwrite a program in python to multiplication of matrices python matrix multiplication with numpynumpy matrix multiplication pythonmatrix simple programs pythonmatrix multiplication algorithm python e2 80 a2 write a python program to do matrix multiplicationmatrick multiplication pythonmatrix multiplication in 5c pythonmatrix multiplication python