Lovely-Numpy: Enhanced Array Representation

0.2.22 · active · verified Fri Apr 17

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.

Common errors

Warnings

Install

Imports

Quickstart

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.

import lovely_numpy as ln
import numpy as np

# Apply lovely-numpy's enhanced representation
ln.override_array_repr()

# Create a sample NumPy array
arr = np.random.randn(2, 3, 4) * 100 + 50 # Make it a bit more interesting

# Print the array to see the lovely-numpy formatting
print("Original array:")
print(arr)

# You can also configure its behavior
ln.config(
    precision=2,        # Display 2 decimal places
    colored=True,       # Enable colored output
    threshold=10,       # Apply repr for arrays with > 10 elements
    science_mode=False  # Disable scientific notation for small numbers
)
print("\nArray with custom configuration:")
print(arr)

# Restore original numpy repr for specific sections if needed
ln.restore_array_repr()
print("\nArray after restoring original numpy repr:")
print(arr)

view raw JSON →