juniorNumPy
What is the shape attribute in NumPy?
Updated May 17, 2026
Short answer
Shape describes the dimensions of a NumPy array.
Deep explanation
The shape attribute returns a tuple representing array dimensions. For example, a 2x3 matrix has shape (2,3). It is essential for understanding data structure in machine learning and linear algebra.
Real-world example
Used in reshaping datasets for ML models.
Common mistakes
- Assuming shape modifies data rather than describing it.
Follow-up questions
- How is shape different from size?
- Can shape be changed?