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

np.any/all का इस्तेमाल

any पूछता है "क्या कम से कम एक True है?" और all पूछता है "क्या हर एक True है?"।

In this page:

  1. np.any/all
Syntax
python
np.any(condition_array)
np.all(condition_array)

np.any/all

np.any True return करता है अगर कोई element True हो; np.all True return करता है सिर्फ तभी जब सारे हों। दोनों rows या columns test करने के लिए एक axis argument लेते हैं। Non-zero numbers True count होते हैं।

Note: दो arrays match करते हैं यह check करने के लिए np.all(a == b) या array_equal इस्तेमाल करें।

उदाहरण: np.any/all

python
import numpy as np

a = np.array([[1, 2], [0, 4]])
print(np.any(a == 0), np.all(a > 0))
print(np.all(a > 0, axis=1))
print(np.any(a > 3, axis=0))

# Output:
# True False
# [ True False]
# [False  True]
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. 2-D arrays पर Python का any और all इस्तेमाल करना
  2. यह भूल जाना कि non-zero True है
  3. एक empty array test करना और result गलत judge करना
चैप्टर सारांश
  • any को कम से कम एक True चाहिए
  • all को हर element True चाहिए
  • axis rows या columns test करता है
  • एक empty array का all True है
🔒

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.