← Back to NumPy Course | Chapter 10: Boolean & Comparison | Lesson 4 of 6

np.isnan/isinf का इस्तेमाल

ये functions numeric arrays के अंदर missing values (NaN) और infinite values ढूंढते हैं।

In this page:

  1. np.isnan/isinf
Syntax
python
np.isnan(arr)
np.isinf(arr)

np.isnan/isinf

NaN का मतलब है "not a number" और यह missing या invalid results mark करता है, जबकि inf overflow या एक float zero से division mark करता है। np.isnan, np.isinf, और np.isfinite boolean masks return करते हैं। ध्यान दें कि nan == nan False है, इसलिए इसे detect करने के लिए isnan इस्तेमाल करना ज़रूरी है।

Note: np.nanmean, np.nansum, और इनके जैसे NaN values ignore करते हैं।

उदाहरण: np.isnan/isinf

python
import numpy as np

a = np.array([1.0, np.nan, 3.0, np.inf])
print(np.isnan(a))
print(np.isinf(a))
print(np.isfinite(a))
print(np.nanmean(a[np.isfinite(a)]))

# Output:
# [False  True False False]
# [False False False  True]
# [ True False  True False]
# 2.0
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. == से NaN test करना
  2. NaN को silently एक mean poison करने देना
  3. यह भूल जाना कि inf और nan अलग हैं
चैप्टर सारांश
  • NaN खुद के बराबर नहीं है
  • इसे detect करने के लिए isnan इस्तेमाल करें
  • isinf infinities ढूंढता है
  • nan-prefixed functions NaN ignore करते हैं
🔒

Chapter Quiz — Complete all 6 topics to unlock

0/6 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.