matrix = [[0 for j in range(2)] for i in range(2)] print(matrix)
matrix = [[1 if i == j else 0 for j in range(3)] for i in range(3)] print(matrix)In this example, we use a nested list comprehension to create a 3x3 matrix with ones on the main diagonal and zeros elsewhere. As mentioned earlier, Python Matrix is built-in to Python and does not require any external package or library.