Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I plot pytorch tensor?

I would like to plot pytorch gpu tensor:

input= torch.randn(100).to(device)
output = torch.where(input>=0, input, -input)

input = input.('cpu').detach().numpy().copy()
output = output.('cpu').detach().numpy().copy()

plt.plot(input,out)

However I try to convert those tensors into cpu, numpy, it does not work. How can I plot the tensors ?

like image 306
Jenny I Avatar asked Jul 25 '26 19:07

Jenny I


1 Answers

Does this work?

plt.plot(input.cpu().numpy(),output.cpu().numpy())

Alternatively you can try,

plt.plot(input.to('cpu').numpy(),output.to('cpu').numpy())
like image 188
anarchy Avatar answered Jul 27 '26 08:07

anarchy



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!