Creating a Matrix using Numpy in Python

Creating a Matrix using Numpy in Python – Create a two-dimensional array:

  • Example How to Create a two-dimensional array
    import numpy as np
    matrix = np.array([[1, 2], [1, 2], [1, 2]])
    print(matrix)
    
    matrix_object = np.mat([[1, 2],[1, 2],[1, 2]])
    print(matrix)
    
    matrix = np.matrix([[1, 2], [1, 2], [1, 2]])
    print(matrix)

The matrix data structure is not recommended because arrays are the de facto standard data structure of NumPy. and The vast majority of NumPy operations return arrays, not matrix objects.