﻿ NumPy: Generate a matrix product of two arrays - w3resource

# NumPy: Generate a matrix product of two arrays

## NumPy Mathematics: Exercise-15 with Solution

Write a NumPy 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]]
```

Pictorial Presentation:

Python Code Editor:

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

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+++"
str.strip()

print(str)```

Output:

`+++Welcome python+++`