Source code for aphin.utils.print_matrices

import numpy as np
import logging


[docs] def matprint(name, mat, decimals=2): """ Pretty print a matrix with specified formatting. This function prints the matrix with a label and formats the floating-point numbers to a specified number of decimal places for better readability. Parameters: ----------- name : str Label to display before printing the matrix. mat : numpy.ndarray The matrix to be printed. decimals : int, optional Number of decimal places to format the floating-point numbers. Defaults to 2. Examples: --------- >>> mat = np.array([[1.123456, 2.345678], [3.456789, 4.567890]]) >>> matprint("My Matrix", mat, decimals=3) My Matrix: [[1.123 2.346] [3.457 4.568]] """ print(f"\n{name}:") with np.printoptions( precision=4, suppress=False, formatter={"float": ("{:0." + str(decimals) + "f}").format}, linewidth=100, ): print(mat)