import numpy as np
import warnings
warnings.filterwarnings("ignore")
# Define a matrix
A = np.array([[1, 2, 3],
[4, 5, 6],
[7, 8, 9]])
# Perform row reduction to get the matrix in row echelon form
for i in range(len(A)):
# Find pivot element
pivot = A[i][i]
# Divide row by pivot element
A[i] = A[i]/pivot
# Subtract row from other rows to get zeros below pivot element
for j in range(i+1, len(A)):
factor = A[j][i]
A[j] = A[j] - factor * A[i]
# Count the number of non-zero rows to get the rank of the matrix
rank = 0
for row in A:
if not all(val == 0 for val in row):
rank += 1
print("The rank of the matrix is:", rank)