NumPy Indexing, Slicing and Operations
NumPy Indexing, Slicing और Operations
What is NumPy Indexing and Slicing?
NumPy Indexing and Slicing means indexing and slicing select specific values, rows, columns or ranges from NumPy arrays.
In real programs, this topic helps in selecting array rows and columns. Learn the idea first, then type the program yourself and compare the output.
| Point | Details |
|---|---|
| Course Area | Data Science Tools and concepts used to analyse, clean and present data. |
| Main Use | selecting array rows and columns |
| Example File | numpy-indexing.py |
| Practice Focus | Run, change values, and explain the output line by line. |
Why should you learn this?
- It is useful for selecting array rows and columns.
- It connects with filtering numbers.
- It improves your ability to read, write and debug Python programs.
Important Terms
These terms are used directly in this lesson. Understand them before memorising the code.
| Term | Meaning |
|---|---|
| index | Labels used to identify rows. |
| slice | slice is an important term in this topic. |
| 2D array | 2D array is an important term in this topic. |
| row | Horizontal record in a table or array. |
| column | Vertical field in a table or array. |
Syntax / Basic Pattern
The simple pattern is: prepare data, apply the concept, then show the result.
import numpy as np
data = np.array([[10, 20, 30], [40, 50, 60]])
print("First row:", data[0])
print("Second column:", data[:, 1])
print("Value:", data[1, 2])Complete Example Program
import numpy as np
data = np.array([[10, 20, 30], [40, 50, 60]])
print("First row:", data[0])
print("Second column:", data[:, 1])
print("Value:", data[1, 2])Expected Output
Program Explanation
import numpy as npimports ready-made features from a module/library.data = np.array([[10, 20, 30], [40, 50, 60]])stores a value in data.print("First row:", data[0])displays information or calculated result on the screen.print("Second column:", data[:, 1])displays information or calculated result on the screen.print("Value:", data[1, 2])displays information or calculated result on the screen.
Where will you use it?
- Selecting array rows and columns.
- Filtering numbers.
- Working with image pixels.
Common Mistakes
- Analysing data before checking missing values, duplicates and data types.
- Changing original data without keeping a clean copy.
- Creating charts without title, labels or explanation.
Practice Tasks
- Type the program in
numpy-indexing.pyand run it. - Change input values or sample data and observe the new output.
- Create one example related to selecting array rows and columns.
- Write 5 lines explaining the logic in your own words.
Summary
NumPy Indexing and Slicing is not a theory-only topic. You should be able to explain the meaning, write the example, run it successfully, and use it in a small practical program.
NumPy Indexing और Slicing क्या है?
NumPy Indexing और Slicing ka matlab hai: Indexing and slicing select specific values, rows, columns or ranges from NumPy arrays. Simple words me, ye topic practical Python programs likhne me direct use hota hai.
Is topic ko sirf definition ke liye nahi, balki selecting array rows and columns jaise real examples ke liye practice karein.
यह क्यों सीखना जरूरी है?
- Ye selecting array rows and columns me kaam aata hai.
- Ye filtering numbers se bhi connected hai.
- Isse aap code ka output aur errors better samajh paate hain.
Important Terms
| Term | Meaning |
|---|---|
| index | Labels used to identify rows. |
| slice | slice is an important term in this topic. |
| 2D array | 2D array is an important term in this topic. |
| row | Horizontal record in a table or array. |
| column | Vertical field in a table or array. |
Syntax / Basic Pattern
Basic idea: pehle data तैयार करें, phir Python logic apply करें, aur finally result display करें.
import numpy as np
data = np.array([[10, 20, 30], [40, 50, 60]])
print("First row:", data[0])
print("Second column:", data[:, 1])
print("Value:", data[1, 2])Complete Example Program
import numpy as np
data = np.array([[10, 20, 30], [40, 50, 60]])
print("First row:", data[0])
print("Second column:", data[:, 1])
print("Value:", data[1, 2])Expected Output
Program Explanation
import numpy as npimports ready-made features from a module/library.data = np.array([[10, 20, 30], [40, 50, 60]])stores a value in data.print("First row:", data[0])displays information or calculated result on the screen.print("Second column:", data[:, 1])displays information or calculated result on the screen.print("Value:", data[1, 2])displays information or calculated result on the screen.
Practical Uses
- Selecting array rows and columns.
- Filtering numbers.
- Working with image pixels.
Common Mistakes
- Analysing data before checking missing values, duplicates and data types.
- Changing original data without keeping a clean copy.
- Creating charts without title, labels or explanation.
Practice Tasks
- Program ko
numpy-indexing.pyfile me type karke run karein. - Values change karke output compare karein.
- selecting array rows and columns par ek छोटा example banayen.
- Logic ko apne words me 5 lines me likhein.
सारांश
NumPy Indexing and Slicing ko tab complete maanenge jab aap iska meaning, example, output aur practical use clearly explain kar saken.