44. Install PyTorch and First Tensors
44.3 Create and Shape Tensors
Why. Shape bugs cause most beginner crashes. Practice view/reshape gently.
What. reshape / view change how numbers are grouped without changing the count. Batch dimension is usually first: (batch, features).
How.
Play with shapes
- Create a length-6 vector.
- Reshape to (2, 3).
- Add a batch of 4 rows × 3 features.
import torch
v = torch.arange(6.0)
print(v.reshape(2, 3))
batch = torch.randn(4, 3)
print("batch shape", batch.shape)
What you should see. A 2×3 matrix and a 4×3 batch — the pattern used when training on mini-batches.