"""Affichage lisible des nombres complexes dans les extraits de la leçon."""

import numpy as np


def fmt(z):
    """Un nombre arrondi à 3 décimales, sans partie nulle ni « -0 » : 0.6, 0.8j, 0.6+0.8j."""
    z = complex(np.round(complex(z), 3))
    re, im = z.real + 0.0, z.imag + 0.0
    if im == 0:
        return f"{re:g}"
    if re == 0:
        return f"{im:g}j"
    return f"{re:g}{im:+g}j"


def show(array):
    """Un vecteur ou une matrice, écrit avec fmt : [[0.6, 0.8j], [0.8j, 0.6]]."""
    array = np.asarray(array)
    if array.ndim == 1:
        return "[" + ", ".join(fmt(z) for z in array) + "]"
    return "[" + ", ".join(show(row) for row in array) + "]"
