2x3 Matrix Times 3x2 Matrix
Multiplication of ii Matrices in Single line using Numpy in Python
Matrix multiplication is a lengthy process where each element from each row and column of the matrixes are to exist multiplied and added in a sure fashion. For matrix multiplication, the number of columns in the first matrix must be equal to the number of rows in the second matrix. The result matrix has the number of rows of the first and the number of columns of the second matrix.
For smaller matrices nosotros may blueprint nested for loops and observe the result. For bigger matrices we need some built in functionality in python to tackle this. We will run into both approaches below.
Using for Loop
Nosotros take two matrices of dimension 2x3 and 3x2 (rows x columns). The result of matrix multiplication is a 2x2 matrix. Nosotros accept a nested for loop designed to become through the columns of A and rows of B and add the products of the values in those rows and columns.
Example
Live Demo
#matrix A with 2 rows A = ([v,10,xv],[20,25,30]) #matrix B with ii columns B = ([4,8],[12,x],[14,16]) issue = [[0 for x in range(2)] for y in range(ii)] for i in range(len(A)): # iterate through columns of A for j in range(len(B[0])): # iterate through rows of B for k in range(len(B)): result[i][j] += A[i][k] * B[k][j] for r in result: print(r)
Output
Running the above code gives us the following result:
[350, 380] [800, 890]
Using Numpy
Numpy has a in-built function named dot, that carries out the matrix multiplication. Our number of lines of program becomes very less and the syntax is besides very simple.
Example
Alive Demo
import numpy as np #matrix A matrix_A = ([5,10,15],[20,25,30]) #matrix B matrix_B = ([4,8],[12,10],[14,xvi]) result = np.dot(matrix_A,matrix_B) # Result print(effect)
Output
Running the higher up lawmaking gives us the following event:
[[350 380] [800 890]]
Updated on 07-Jan-2020 06:41:xvi
- Related Questions & Answers
- Multiplication of two Matrices using Numpy in Python
- Multiplication of ii Matrices using Java
- How to Add together Ii Matrices using Python?
- How to Multiply 2 Matrices using Python?
- Python program multiplication of two matrix.
- Python program to multiply two matrices
- Bandy two variables in one line in using Python?
- Compare ii int arrays in a unmarried line in Coffee
- Compare two short arrays in a single line in Java
- Compare two double arrays in a unmarried line in Java
- Compare two long arrays in a single line in Java
- Compare two float arrays in a single line in Java
- Compare two char arrays in a unmarried line in Java
- Compare two-byte arrays in a single line in Java
- How to multiply 2 matrices using pointers in C?
2x3 Matrix Times 3x2 Matrix,
Source: https://www.tutorialspoint.com/multiplication-of-two-matrices-in-single-line-using-numpy-in-python
Posted by: ruthclowboulat.blogspot.com

0 Response to "2x3 Matrix Times 3x2 Matrix"
Post a Comment