Plotting a tensor

Hello! I have a tensor avg_act['a'] of size (64,2000) and I try

plt.imshow(avg_act['a'][idx1])

and get this error: Invalid shape (128,) for image data
How can I fix this?

Hi,
your tensor needs to have at least 2 dimension for imshow. Check the docs for reference.

now that I have one dimension what should I use? Is there anything?

You could just unsqueeze the data you pass to imshow.

I don’t know how. Could you please explain?

By using example_tensor.unsqueeze(-1) for instance.

thank you! I did that and now the code works without errors but it doesn’t show any plots. what is wrong? I’m using python 3.7 on CPU.

Have you forgotten to use plt.show()?

Yes! Thank you it works now

1 Like