{"id":9906,"library":"lovely-numpy","title":"Lovely-Numpy: Enhanced Array Representation","description":"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.","status":"active","version":"0.2.22","language":"en","source_language":"en","source_url":"https://github.com/xl0/lovely-numpy","tags":["numpy","data science","debugging","visualization","repr","developer tools"],"install":[{"cmd":"pip install lovely-numpy","lang":"bash","label":"Install stable version"}],"dependencies":[{"reason":"lovely-numpy is a wrapper/enhancement for numpy arrays and requires it to function.","package":"numpy","optional":false}],"imports":[{"note":"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()'.","symbol":"lovely_numpy","correct":"import lovely_numpy as ln"},{"note":"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.","wrong":"from lovely_numpy import override_array_repr\noverride_array_repr()","symbol":"override_array_repr","correct":"import lovely_numpy as ln\nln.override_array_repr()"}],"quickstart":{"code":"import lovely_numpy as ln\nimport numpy as np\n\n# Apply lovely-numpy's enhanced representation\nln.override_array_repr()\n\n# Create a sample NumPy array\narr = np.random.randn(2, 3, 4) * 100 + 50 # Make it a bit more interesting\n\n# Print the array to see the lovely-numpy formatting\nprint(\"Original array:\")\nprint(arr)\n\n# You can also configure its behavior\nln.config(\n    precision=2,        # Display 2 decimal places\n    colored=True,       # Enable colored output\n    threshold=10,       # Apply repr for arrays with > 10 elements\n    science_mode=False  # Disable scientific notation for small numbers\n)\nprint(\"\\nArray with custom configuration:\")\nprint(arr)\n\n# Restore original numpy repr for specific sections if needed\nln.restore_array_repr()\nprint(\"\\nArray after restoring original numpy repr:\")\nprint(arr)\n","lang":"python","description":"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."},"warnings":[{"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.","message":"lovely-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.","severity":"gotcha","affected_versions":"All versions"},{"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.","message":"Configuration 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.","severity":"gotcha","affected_versions":"All versions"},{"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.","message":"While 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.","severity":"gotcha","affected_versions":"All versions"}],"env_vars":null,"last_verified":"2026-04-17T00:00:00.000Z","next_check":"2026-07-16T00:00:00.000Z","problems":[{"fix":"Ensure `import lovely_numpy as ln` and `ln.override_array_repr()` are both present and executed before you print NumPy arrays.","cause":"The `ln.override_array_repr()` function, which activates the custom representation, was not called or was called too late.","error":"Arrays are not formatted by lovely-numpy; they still look like standard NumPy output."},{"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.","cause":"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.","error":"lovely-numpy output suddenly reverted to default NumPy representation, or output is inconsistent."},{"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.","cause":"The default configuration of lovely-numpy does not match desired output, or `ln.config()` was not used effectively.","error":"Output is too verbose / not verbose enough / wrong precision / lacks color."}]}