Why exactly does matplotlib need the channels to be in the last dimension?

Why exactly does matplotlib need the channels to be in the last dimension?

Matplotlib expects the channels of any image to be at the last, be it from a tensor or an array, that’s how the pillow library is implemented I guess.

You can refer these links for reference:

https://pytorch.org/docs/stable/tensors.html#torch.Tensor.permute

https://matplotlib.org/3.1.1/tutorials/introductory/images.html

Note : from the last link, even the same expectancy of image channels as the last dimension is there. So, it’s not only for tensors , but from arrays too.

Also, you can alternatively use OpenCV which by default uses 3 channels for plotting images . Take a look here : https://stackoverflow.com/questions/18870603/in-opencv-python-why-am-i-getting-3-channel-images-from-a-grayscale-image