🔵 Data Science · Lesson 36
NumPy Indexing, Slicing और Operations
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 करें.
Basic Pattern
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
Python – numpy-indexing.py
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
First row: [10 20 30]
Second column: [20 50]
Value: 60
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.
💻 लाइव कोड एडिटर
इस पेज के प्रोग्राम यहीं तैयार हैं — चलाएँ, बदलें और सीखें। कुछ भी इंस्टॉल किए बिना।
OneCompiler द्वारा संचालित। कोड एडिटर में अपने आप आ जाता है — Run दबाकर आउटपुट देखें। अगर एडिटर न खुले तो नए टैब में खोलें.