Tensor = np.array

Reshape .view()

x = torch.randn(4, 4)
y = x.view(16)
z = x.view(-1, 8)  # the size -1 is inferred from other dimensions
print(x.size(), y.size(), z.size())

1-item → python value .item()

x = torch.randn(1)
print(x)
print(x.item())

https://pytorch.org/tutorials/beginner/blitz/autograd_tutorial.html

torch.Tensor is the central class of the package. If you set its attribute .requires_grad as True, it starts to track all operations on it. When you finish your computation you can call .backward() and have all the gradients computed automatically. The gradient for this tensor will be accumulated into .grad attribute.

To prevent tracking history (and using memory), you can also wrap the code block in with torch.no_grad():. This can be particularly helpful when evaluating a model because the model may have trainable parameters with requires_grad=True, but for which we don’t need the gradients.

https://pytorch.org/tutorials/beginner/blitz/neural_networks_tutorial.html

A typical training procedure for a neural network is as follows: