Lovely Tensors

0.1.22 · active · verified Fri Apr 17

lovely-tensors is a Python library that provides "syntax sugar" for PyTorch tensors, enhancing their default `repr` for better readability, debugging, and development. It adds features like rich, colored, and pretty-printed output, automatic batching, and shape inference. As of version 0.1.22, it is actively maintained with frequent minor releases focusing on new features and improvements.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to import `lovely-tensors`, enable its global monkey-patching for `torch.Tensor`'s `__repr__`, and then print PyTorch tensors to see the enhanced, colored output. It also shows how to use `lt.lovely()` for explicit pretty-printing.

import torch
import lovely_tensors as lt

# Enable beautiful tensor repr globally
lt.monkey_patch()

# Create some tensors
a = torch.randn(2, 3, 4)
b = torch.randint(0, 10, (1, 5), dtype=torch.int)

print(f"Tensor a:\n{a}")
print(f"Tensor b:\n{b}")

# You can also explicitly print lovely tensors without monkey-patching
# For demonstration, let's pretend monkey_patch wasn't called:
# import lovely_tensors as lt
# lt.lovely(torch.tensor([1,2,3]))

view raw JSON →