Chapter 6: Introduction to NumPy
Original notes — ready CBSE (NCERT, English Medium) • Class 11 • Computer Science • Book: Informatics Practices
Chapter 6: Introduction to NumPy — EG's own notes, in simple words
Book: Informatics Practices (CBSE, Class 11) | Chapter 6 | Medium: English

Diagram (labels on the image): Diagram (labels on the image): NumPy at work — an array of numbers, one operation applied to all of them, and the result array.

One step for the whole column: why arrays beat loops for numbers.
1. 1. Why NumPy exists
Python lists are flexible but slow for large numerical work, because each item is a separate object. NumPy (Numerical Python) provides arrays: ordered collections of numbers of one type, stored compactly and processed in fast, ready-made operations. For marks, temperatures or sensor readings, arrays beat lists.
Original example: a list of 40 marks and an array of 40 marks look similar, but the array can add, average or compare all 40 in one step, while the list needs an explicit loop.
2. 2. Creating arrays
Arrays are created with numpy.array(): import numpy as np; marks = np.array([70, 85, 90, 88]) makes a one-dimensional array. np.zeros(5) makes five zeros, np.ones(4) makes four ones, and np.arange(1, 10, 2) gives 1, 3, 5, 7, 9. Two-dimensional arrays are lists of lists: np.array([[70, 85], [90, 88]]) is a 2-row table.
Every array has a shape (rows and columns, e.g. (2, 2)), a size (total items) and a dtype (the single data type of its items).
3. 3. Array operations
Arrays support element-wise arithmetic: marks + 5 adds 5 to every mark at once, and marks1 + marks2 adds matching items. Aggregate functions summarise: np.sum(), np.mean(), np.max(), np.min(). Boolean indexing selects items meeting a condition: marks[marks >= 90] gives only marks 90 or above.
Slicing works like lists: marks[1:3] gives items 1 and 2. Reshaping changes shape without changing data: an array of 6 items can reshape to (2, 3) or (3, 2).
4. 4. Arrays versus lists
Arrays require one data type, support whole-array operations, and run faster on numbers. Lists accept mixed types and are better for general collections. For numerical data analysis — the heart of this book — arrays are the right tool, and they connect directly to tables and charts in later work.
At a glance — chart / table
| Task | NumPy way (original example) | Result |
|---|---|---|
| Create | np.array([70, 85, 90]) | Array of 3 marks |
| Add 5 to all | marks + 5 | [75, 90, 95] |
| Average | np.mean(marks) | 81.67 |
| Select high marks | marks[marks >= 90] | [90] |
| Shape of 2x2 | arr.shape | (2, 2) |
Key Terms / Important Terms
- NumPy — A Python library for fast numerical arrays.
- Array — An ordered collection of same-type numbers, processed together.
- Shape — The dimensions of an array, e.g. (2, 3).
- dtype — The single data type of an array's items.
- Element-wise operation — An operation applied to every item at once.
- Boolean indexing — Selecting array items with a True/False condition.
- Reshape — Changing an array's shape without changing its data.
Remember
- import numpy as np is the standard first line.
- Arrays: one dtype, compact, whole-array operations — faster than lists for numbers.
- Shape (rows, columns); size = total items; slicing excludes the stop.
- marks[marks >= 90] selects by condition — Boolean indexing.
Exam Tip / Common Mistake
Common mistake: forgetting import numpy as np before using np.array. Without the import, every np. name fails — examiners often plant this in error-spotting questions.
Practice set — try it yourself
- Write original code to create an array of four marks and print its mean. Hint: Hint: Import numpy as np, create with np.array, summarise with np.mean.
- For marks = np.array([70, 85, 90, 88]), what does marks[marks >= 85] give? Hint: Hint: Boolean indexing keeps only items meeting the condition.
- Distinguish an array from a list in two points. Hint: Hint: One dtype and whole-array operations are two.
- An array has 6 items. Give two shapes it can reshape to. Hint: Hint: The total must stay 6.
- What does marks + 10 do to an array, and why is this faster than a list loop? Hint: Hint: One operation applies to every item at once.
Questions with Answers
- What is NumPy, and why is it used for numerical data? Answer: Answer: NumPy is a Python library providing arrays for numerical work. Arrays store same-type numbers compactly and support whole-array operations, making them faster and simpler than lists for large numerical tasks.
- Write original code to create an array [70, 85, 90, 88] and print its sum and mean. Answer: Answer: import numpy as np; marks = np.array([70, 85, 90, 88]); print(np.sum(marks)); print(np.mean(marks)). The sum is 333 and the mean is 83.25.
- What are shape, size and dtype of an array? Answer: Answer: Shape gives the dimensions, e.g. (2, 3) for 2 rows and 3 columns. Size is the total number of items. dtype is the single data type of all items, such as int or float.
- Explain Boolean indexing with an original example. Answer: Answer: Boolean indexing selects items meeting a condition. For marks = np.array([70, 85, 90, 88]), marks[marks >= 90] tests each item and returns only [90].
- Distinguish an array from a list. Answer: Answer: An array holds items of one dtype and supports whole-array operations such as marks + 5, running fast on numbers. A list holds mixed types and needs explicit loops for the same operations.

