lovely-numpy (version 0.2.22) is a utility library that enhances the default string representation of NumPy arrays, making them significantly more readable and debug-friendly. It achieves this by overriding `np.ndarray.__repr__` to display arrays with improved formatting, optional colors, configurable precision, and a more compact summary for large arrays. The library is actively maintained and released as needed for improvements and bug fixes, focusing on ease of use for interactive data exploration.
pip install lovely-numpyVerified import paths — ran on the pinned version, not inferred.
Demonstrates how to activate the lovely-numpy array representation and configure its display options like precision and coloring. It also shows how to revert to the default NumPy representation.
Ensure `ln.override_array_repr()` is called after any other library that might also modify `np.ndarray.__repr__`. Use `ln.restore_array_repr()` to temporarily revert or debug conflicts.
Be mindful of the global nature of `ln.config()`. For isolated testing or specific contexts, consider applying and restoring configurations explicitly, or using `ln.restore_array_repr()` and re-applying `ln.override_array_repr()` with desired settings.
For performance-critical code paths, consider calling `ln.restore_array_repr()` or using `ln.config(skip_repr_for_small_arrays=True)` if you only want it for specific arrays. lovely-numpy's default behavior handles large arrays efficiently by summarizing them, but custom configurations might impact this.
Ensure `import lovely_numpy as ln` and `ln.override_array_repr()` are both present and executed before you print NumPy arrays.
Re-call `ln.override_array_repr()` after the conflicting operation. Identify and manage `__repr__` overrides if multiple libraries are involved, ensuring lovely-numpy's override is the last one applied.
Use `ln.config(param=value, ...)` after `ln.override_array_repr()` to adjust settings like `precision`, `threshold`, `colored`, `science_mode`, etc., to your preference. Refer to the documentation for available configuration options.