matrix multiplication in python

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

showing results for - "matrix multiplication in python"
Santiago
08 Mar 2017
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
Emiliano
13 Jan 2017
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
Guadalupe
31 Feb 2016
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 multiplicationnumpy multiply n no of matrixmultiplication matrix pythonhow to code matrix multiplication in python e2 80 a2 write a python program to do matrix multiplicationmatrix multiplication in numpymatrix multiplication list comprehension pythonmatrix multiplication using pythonmatrix product in numpyhow to multiply to matrix in pythonpython matrix multiplicationpython program for matrix multiplicationthree matrix multiplication pythonmultiplication of matrix python program for matrix multiplication pythonnumpy multiply matrixesmatrix multiplication examplemultiplication of two matrices in pythonwrite a python program to perform matrix multiplicationpython2 matrix multiplicationnumpy multiply matrixnumber of multiplication in matrixpython code for matrix multiplicationnumpy multiply two arraysmatrix simple programs pythonhow to do matrix multiplication in pythonmatrix multiplcation numpynumpy matrix vector multiplicationpython program for multiplication of matricesmatrix multiplication pythonpython matrix multiplication atmatrices multiplication in pythonarray multiplication in mumpyto write a python program to perform matrix multiplication matrix multiplication with numpymultiplication of matrix numpymatrix row column multiplication in pythonmultiplication of matrix in pythonpython library matrix multiplicationmultiply matrices python 2cmatrix multiplicationwrite a python program to perform matrix multiplication matrix multiplication program pythonhow to multiply matrix in pythonpython numpy matrix multiplicationpython prg to multply matricesmatriz multiplication in pythonmatrix multiplication python numpyhow to matrix multiplication in pythonstrassen 27s matrix multiplication pymatrix multiplication python 40numpy python matrix multiplicationpython matrix multiplication with numpymultiplication pythonmultiplication of matrixprogram for matrix multiplication in pythonmatrix multiplication in 5c pythonnumpy array multiplicationpython multiplication matrixmatrix multiplication of two numpy arrayshow to do matrix multiplication numpymatrix matrix multiplication pythonhow to matrix multiply in numpymatrix multiplication in python with numpymatrix multiplication python using numpy3 2a3 matrix multiplication in pythonmatrix multiplication in pythonmultiply to matrices in pythonmatrix multiplication program in pythonmultiply matrices in pythonmultiplying matrices in pythonwrite a program in python to multiplication of matrices multiply matrix pythonmatrix vector product numpypythonmatrix multiplicationmatrix multiplication in python using numpynumpy matrix multiplication codematrix multiplication numpyhow to multiply 2 matrices in python using numpynumpy matrix multiplicationpython matrix multiplication libraryhow to multiply 2 arrays in python numpypython multiply matricesmatrix multiplication in python numpymultiply matrix in pythonto write a python program to perform matrix multiplicationmatrix multipication numpyhow to print directly matrix multiplication in pythonhow to multiply array with matrix in pythonpython matrix multipicationmatrix multiplication algorithm pythonmatrix multi as np array for pythonmatrix product numpypython multiply matrix how to multiply matrices pythonnumpy matrix multiplication pythontwo matrix multiplication in pythonpython matrix multiplication numpymultiplication of matrices in python 3how to do matrix multiplication in numpymatrix multiplication pyhow to matrix multiplication in nupymatrix mulptilication numymatrick multiplication pythonuse numpy for matrix multiplicationmatrix multiplication in python