You can use NumPy .array() function to make a matrix in NumPy.

The syntax for making a matrix in NumPy:

np.array([[element1, element2, elementn],[element1, element2, elementn]])

The following syntax can be demonstrated using an example in Python:

import numpy as np

matrix_variable = np.array([[1, 2, 3], [4, 5, 6], [7, 8, 9]])

matrix_variable

Checking the shape of the NumPy array,

matrix_variable.shape

This is how you create a 3×3 matrix in NumPy. You can change the number of rows and columns according to your needs.

In Conclusion

Do you have any problems making a NumPy matrix? Let us know in the comment section below.

LEAVE A REPLY

Please enter your comment!
Please enter your name here