NumPy: Multiply a 5x3 matrix by a 3x2 matrix and create a real matrix product

NumPy Mathematics: Exercise-11 with Solution

Write a NumPy program to multiply a 5x3 matrix by a 3x2 matrix and create a real matrix product.

Sample Solution:-

Python Code:

import numpy as np
x = np.random.random((5,3))
print("First array:")
y = np.random.random((3,2))
print("Second array:")
z = np.dot(x, y)
print("Dot product of two arrays:")

Sample Output:

First array:                                                           
[[ 0.44349753  0.81043761  0.00771825]                                 
 [ 0.64004088  0.86774612  0.19944667]                                 
 [ 0.61520091  0.24796788  0.93798297]                                 
 [ 0.22156999  0.61318856  0.82348994]                                 
 [ 0.91324026  0.13411297  0.00622696]]                                
Second array:                                                          
[[ 0.73873542  0.06448186]                                             
 [ 0.90974982  0.06409165]                                             
 [ 0.22321268  0.39147412]]                                            
Dot product of two arrays:                                             
[[ 1.06664562  0.08356133]                                             
 [ 1.30677176  0.17496452]                                             
 [ 0.88942914  0.42275803]                                             
 [ 0.90534318  0.37596252]                                             
 [ 0.79804212  0.06992065]]

Python Code Editor:

Have another way to solve this solution? Contribute your code (and comments) through Disqus.

Previous: Write a NumPy program to get the floor, ceiling and truncated values of the elements of an numpy array.
Next: Write a NumPy program to multiply a matrix by another matrix of complex numbers and create a new matrix of complex numbers.

What is the difficulty level of this exercise?

Test your Python skills with w3resource's quiz

Python: Tips of the Day

Getting rid of unwanted characters:

You can get rid of whitespaces or any specific character using strip methods in Python. You can use either plain strip for both sides, lstrip for the left side and rstrip for the right side only.

str="+++Welcome python+++"



+++Welcome python+++