Registry / data / lovely-numpy

lovely-numpy

JSON →
library0.2.24pypypi✓ verified 85d ago

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-numpy
INSTALL
IMPORT
SIG · LOVELY-NUMPY
L
lovely-numpy
datapythonv0.2.24
Install
7.9s avg
Import
3057ms
Disk
182MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v0.2.24 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.910 runs
installs and imports cleanly · install 0.0s · import 2.523s · 178.6MB
glibc
py 3.103.910 runs
installs and imports cleanly · install 7.9s · import 2.368s · 171MB
182MB installed
● package 182MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

lovely_numpy
import lovely_numpy as ln
The common and recommended practice is to import the module with the alias 'ln' to access all its features like 'ln.override_array_repr()' and 'ln.config()'.
override_array_repr
import lovely_numpy as ln ln.override_array_repr()
from lovely_numpy import override_array_repr override_array_repr()
While direct import is possible, using the 'ln' alias (e.g., `ln.override_array_repr()`) is preferred for consistency and access to other lovely-numpy utilities.

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)
Debug
Known issues
gotchalovely-numpy globally overrides `np.ndarray.__repr__`, which can conflict with other libraries or user code that also modifies this attribute. The last library to set `__repr__` will take precedence.
fix
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.
affects: All versions
gotchaConfiguration changes made via `ln.config()` affect the global state of lovely-numpy, impacting all subsequent array representations. This can lead to unexpected behavior in multi-threaded environments or within tests if not managed.
fix
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.
affects: All versions
gotchaWhile designed for readability, processing the `__repr__` of extremely large NumPy arrays (e.g., millions of elements) can introduce a minor performance overhead, especially if complex formatting or coloring is enabled, compared to the default, simpler NumPy representation.
fix
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.
affects: All versions
Errors
Common errors & fixes
Arrays are not formatted by lovely-numpy; they still look like standard NumPy output.
The `ln.override_array_repr()` function, which activates the custom representation, was not called or was called too late.
fix
Ensure `import lovely_numpy as ln` and `ln.override_array_repr()` are both present and executed before you print NumPy arrays.
lovely-numpy output suddenly reverted to default NumPy representation, or output is inconsistent.
Another library or a part of your code might have called `ln.restore_array_repr()` or globally overridden `np.ndarray.__repr__` after lovely-numpy was activated.
fix
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.
Output is too verbose / not verbose enough / wrong precision / lacks color.
The default configuration of lovely-numpy does not match desired output, or `ln.config()` was not used effectively.
fix
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.
Upgrade
Version history
0.2.24latest on PyPI · released May 15, 2026
Audit
Dependencies
numpyrequiredlovely-numpy is a wrapper/enhancement for numpy arrays and requires it to function.
Agent activity
7 hits · last 30 days
node
6
Resources
lovely-numpy — pip install lovely-numpy · libregistry