Have you ever tried to plot a PyTorch tensor with matplotlib like: plt.plot(tensor) and then received the following error? AttributeError: 'Tensor' object has no attribute 'ndim' You can get around this easily by letting all PyTorch tensors know how to respond to ndim like this: torch.Tensor.ndim = property(lambda self: len(self.shape)) Basically, this uses the property decorator to create ndim as a property which reads its value as the length of self.
Python is a great language to build command-line tools in as it’s very expressive and concise. You want to have the ability to parse arguments in your scripts as you don’t want to hard-code the relevant variable values to make the tool useful. So how do we go about this in Python? It’s easily done using the argparse module. With argparse, you define the different arguments which you expect, their default values and their shortcuts to call them.
Sometimes it happens that Vim freezes / gets stuck / doesn’t react and you might wonder what is going on. Recently, I figured out that this happens for me when I accidentally pressed Ctrl + S. It turns out that this is an old legacy features back from the slow days of computing where ressources were really scarce and you sometimes wanted to freeze the output of one program to help with your ressources.