midPyTorch
What is torch.stack vs torch.cat?
Updated May 17, 2026
Short answer
stack adds a new dimension; cat concatenates along existing dimension.
Deep explanation
stack increases rank, cat preserves rank but extends size.
Real-world example
Used in batching tensors or merging features.
Common mistakes
- Confusing output shapes.
Follow-up questions
- When to use stack?
- Does cat require same shape?