← PyTorch learning pathPyTorch · Module 2 of 10
Tensors
Create and manipulate tensors on CPU and GPU.
📖 Key ideas
- torch.tensor([1, 2, 3]) creates a tensor.
- Shapes: x.shape; reshape with x.view or x.reshape.
- Move to GPU: x.to("cuda").
- NumPy interop: torch.from_numpy, x.numpy().
- Operations are vectorised and broadcast like NumPy.
💡 Real-life example: Tensors are NumPy arrays that can also travel to the GPU and remember gradients.
TensorMulti-dimensional array
.to(device)Moves tensor to CPU/GPU
view/reshapeChange tensor shape
dtypeData type like float32