← Back to NumPy Course | Chapter 12: Advanced Topics | Lesson 5 of 7

Masked Arrays क्या हैं

Masked arrays आपको bad या missing values hide करने देते हैं ताकि calculations इन्हें skip करें।

In this page:

  1. Masked Arrays
Syntax
python
masked = np.ma.masked_array(data, mask=boolean_mask)
masked.mean()

Masked Arrays

np.ma.masked_array data को एक boolean mask से pair करता है; masked entries को mean और sum जैसे functions ignore करते हैं। masked_where और masked_invalid जैसे helpers conditions से masks बनाते हैं। masked values replace करने के लिए .filled() इस्तेमाल करें।

Note: Mask में एक True मतलब value hidden है, एक boolean index के opposite।

उदाहरण: Masked arrays

python
import numpy as np

data = np.array([10, -999, 30, -999, 50])
m = np.ma.masked_where(data == -999, data)
print(m)
print("mean:", m.mean())
print(m.filled(0))

# Output:
# [10 -- 30 -- 50]
# mean: 30.0
# [10  0 30  0 50]
Related Topics
{# common_mistakes/chapter_summary/browser_support: on Hindi pages the view already swaps in the hi_ translation fields (or blanks these out if untranslated), so this renders correctly for both languages without a lang_code check here. #}
आम गलतियां
  1. mask को backwards पढ़ना
  2. यह भूल जाना कि normal functions masks respect नहीं करते
  3. एक plain array में convert करके mask खोना
चैप्टर सारांश
  • Masked entries ignore होती हैं
  • Mask में True एक value hide करता है
  • masked_where masks बनाता है
  • filled masked values replace करता है
🔒

Chapter Quiz — Complete all 7 topics to unlock

0/7 topics done

Complete these topics first:

Login to run this code

C/C++/Java/PHP execution requires a free account. Your code is saved — you'll land right back in the editor after logging in.