One minute
Plot PyTorch tensors with matplotlib
Have you ever tried to plot a PyTorch tensor with matplotlib like:
and then received the following error?
You can get around this easily by letting all PyTorch tensors know how to respond to ndim like this:
Basically, this uses the property
decorator to create ndim as a property which reads its value as the length of self.shape.
Thus, after you define this, a PyTorch tensor has ndim, so it can be plotted like shown here:

Resulting plot output