print the dimensions of the new matrix. construct the largest possible square matrix out of this matrix. in python

main.py
import numpy as np

# original matrix
matrix = np.array([[1, 2, 3],
                    [4, 5, 6],
                    [7, 8, 9],
                    [10, 11, 12]])

# print dimensions of original matrix
original_rows, original_cols = matrix.shape
print(f"Dimensions of original matrix: {original_rows}x{original_cols}")

# construct the largest possible square matrix
max_size = min(original_rows, original_cols)
square_matrix = matrix[:max_size, :max_size]

# print dimensions of square matrix
rows, cols = square_matrix.shape
print(f"Dimensions of square matrix: {rows}x{cols}")
582 chars
20 lines

related categories

gistlibby LogSnag