print pytorch tensors and numpy arrays concisely.
Project description
print_torch
It is often overwhelming to print(tensor)
which may flash your screen and you just don't get any information useful.
Instead, use pt(tensor)
and it will give you the size, dtype, device, min, max, std, mean, whether has nan, etc. in one line.
>>> import torch
>>> from print_torch import pt
>>> tensor = torch.randn((2,3,4,5))
>>> pt(tensor)
tensor(shape=(2, 3, 4, 5), dtype=float32, min=-2.803, max=2.49, std=1.019, mean=-0.06855, data=[-0.8246, -1.135, 0.1368, 1.56, ... ], device="cpu") >>>
It also works for list of numbers and numpy tensors.
If you have a nested dict/list of pytorch/numpy tensors, you can also pt
it, and it will list each element which may be again a tensor in one line.
For example, you can just pt(locals())
in your forward()
function in the breakpoint to know all the stats of your local variables.
Don't hesitate to add this tool to your arsenal!
pip install print_torch
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file print_torch-1.1.tar.gz
.
File metadata
- Download URL: print_torch-1.1.tar.gz
- Upload date:
- Size: 4.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.8.10
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 16f9d82b1e71f643f4f5c58eb27ddcea2339b4c1e3eb8c3244c803eff2be4f22 |
|
MD5 | 92a5f445dd02e16b8f3b66defdad0884 |
|
BLAKE2b-256 | 452b5a347591268ce3ab31921a8dbecbf3c16d533e3ee63e6c39175b771e3d2a |
File details
Details for the file print_torch-1.1-py3-none-any.whl
.
File metadata
- Download URL: print_torch-1.1-py3-none-any.whl
- Upload date:
- Size: 4.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.8.10
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | dbcff112fb7dcf1afc203c2a92fa1844537ab3c950a97aca186c051d68355ab6 |
|
MD5 | 865376df6d7eb34050ae63cc32328283 |
|
BLAKE2b-256 | 2a9c92bd55fc063e56f6ca47613a929024c2dd06e1858756e55c5265a03c5205 |