w3resource logo
Python Exercises

Python NumPy: Generate a matrix product of two arrays

Python NumPy Math, Statistics, Trigonometry and Linear algebra: Exercise-15 with Solution

Write a Python program to generate a matrix product of two arrays.

Sample Solution:-

Python Code:

import numpy as np
x = [[1, 0], [1, 1]]
y = [[3, 1], [2, 2]]
print("Matrices and vectors.")
print("x:")
print(x)
print("y:")
print(y)
print("Matrix product of above two arrays:")
print(np.matmul(x, y))

Sample Output:

Matrices and vectors.                                                  
x:                                                                     
[[1, 0], [1, 1]]                                                       
y:                                                                     
[[3, 1], [2, 2]]                                                       
Matrix product of above two arrays:                                    
[[3 1]                                                                 
 [5 3]] 

Python Code Editor:

Improve this sample solution and post your code through Disqus