How to convert below tensor into numpy array in pytorch?

How to convert below tensor to numpy array in pytorch?
[tensor([[ 0.1191, -0.0661], [-0.2500, 0.0451], [-0.0905, 0.1674], [-0.0326, 0.3001], [ 0.0547, 0.1601]], grad_fn=), tensor([[ 0.1737, 0.1025], [-0.1487, 0.1500], [ 0.1235, 0.1284], [ 0.1825, 0.0397], [-0.0554, 0.2457]], grad_fn=), tensor([[-0.1453, -0.1910],

Hi,

You can use your_tensor.numpy() to convert it to numpy.
Note that since numpy does not support GPU, you will need to send the tensor back to the cpu before converting it with .cpu().
Note as well that since numpy does not support autograd, if you tensor requires gradient, you will need to get a version that do not with .detach().

1 Like