xxxxxxxxxx
# First, let's define the dimensions of the matrix
rows = 3
cols = 4
# Initialize an empty matrix
matrix = []
# Populate the matrix with values
for i in range(rows):
row = []
for j in range(cols):
value = int(input(f"Enter element for row {i+1}, column {j+1}: "))
row.append(value)
matrix.append(row)
# Print the matrix
for row in matrix:
print(row)
xxxxxxxxxx
matrix = [[0 for column in range(3)]for row in range(3)]
# Generates a 3x3 bidimensional array
xxxxxxxxxx
# Method 1: Using nested lists
matrix = [[1, 2, 3],
[4, 5, 6],
[7, 8, 9]]
# Method 2: Using numpy library
import numpy as np
matrix = np.array([[1, 2, 3],
[4, 5, 6],
[7, 8, 9]])