Introduction to NumPy
Class 11 · Informatics Practices
4 ideas in Class 11 Informatics Practices, explained in plain words, with games and quizzes to practise.
Making Arrays
Part of: Arrays Start
Arrays hold same-type grids; shape counts axes; size counts members; arange builds ranges.
Why it matters. Fast maths grids. Shapes known.
Formulas
- shape lists size per dimension, so (3, 2) means 3 rows and 2 columns.
- size equals the product of the shape elements.
Key words
- Numpy array
- : Grids holding same-type items with fast numeric work.
- Dimensions
- : The count of axes, like 2 for rows and columns.
- Shape
- : The per-axis sizes written as a tuple like (3, 2).
- Size
- : The total element count, product of shape sizes.
Try it in two minutes
- List to array?
- Check shape?
- Count size?
Try at home. Array your marks.
Array Maths
Part of: Arrays Start
Plus, times apply member-wise; sum, mean, max aggregate; slicing takes parts.
Why it matters. Whole grids computed. Parts taken.
Formulas
- Element-wise operations need both arrays to share the same shape.
- The star multiplies element by element while @ does matrix multiplication.
Key words
- Element-wise op
- : Plus and times applied to matching positions of two arrays.
- Matrix product
- : True matrix product written with the @ sign.
- Aggregation
- : One-number summaries like sum, mean and max over a grid.
- Slicing part
- : Taking a rectangular part out of a larger array.
Try it in two minutes
- Operate member-wise?
- Aggregate values?
- Slice parts?
Try at home. Double an array.
Indexing 2D Grids
Part of: Index Reshape Build
Comma index picks row, column; colon takes whole rows, columns; reshape reorganises shape.
Why it matters. Cells reached. Shapes changed.
Formulas
- grid[i, j] names the row i, column j element, counting from zero.
- A colon slice like 0:3 takes a span of rows or columns.
Key words
- 2D indexing
- : Comma indexing picking row first and column next.
- Slice range
- : A colon span selecting whole rows or columns at once.
- Reshape
- : Reorganising rows and columns into a new shape.
Try it in two minutes
- Row, column?
- Colon wholes?
- Reshape kept?
Try at home. Index a grid.
Helper Builders
Part of: Index Reshape Build
Zeros, ones fill grids; arange steps ranges; linspace spaces evenly; dtype sets type.
Why it matters. Ready grids fast. Types set.
Formulas
- zeros and ones build float grids by default.
- reshape changes the shape while keeping the same elements.
Key words
- Zeros builder
- : Ready grids filled with zeros for later filling.
- Ones builder
- : Ready grids filled with ones for later scaling.
- Arange builder
- : Evenly stepped ranges built without typing each value.
- Dtype
- : The element kind stored, settable at creation time.
Try it in two minutes
- Fill zeros, ones?
- Step ranges?
- Set type?
Try at home. Build zero grid.
What your child will practise
- Array Maths: Candy Puzzle (Clue Puzzle)
- Array Maths: Candy Quick Fire (Quick Fire)
- Helper Builders: Desert Puzzle (Clue Puzzle)
- Indexing 2D Grids: Ocean Quest (Flip and Match)
- Making Arrays: Ocean Quick Fire (Quick Fire)
- Quiz: Array Maths (8 questions)
- Quiz: Helper Builders (8 questions)
- Quiz: Indexing 2D Grids (8 questions)
- Quiz: Making Arrays (8 questions)