5,323
edits
Line 72: | Line 72: | ||
* For non-scalar items, use <code>my_var.detach().cpu().numpy()</code> | * For non-scalar items, use <code>my_var.detach().cpu().numpy()</code> | ||
* <code>detach()</code> deletes the item from the autograd edge | * [https://pytorch.org/docs/stable/autograd.html#torch.Tensor.detach <code>detach()</code> ]deletes the item from the autograd edge. | ||
* <code>cpu()</code> | * [https://pytorch.org/docs/stable/tensors.html?highlight=cpu#torch.Tensor.cpu <code>cpu()</code>] moves the tensor to the CPU. | ||
* <code>numpy()</code> returns | * [https://pytorch.org/docs/stable/tensors.html#torch.Tensor.numpy <code>numpy()</code>] returns the underlying numpy tensor. | ||
When possible, use functions which return new views of existing tensors rather than making duplicates of tensors: | When possible, use functions which return new views of existing tensors rather than making duplicates of tensors: |