np.any/all का इस्तेमाल
any पूछता है "क्या कम से कम एक True है?" और all पूछता है "क्या हर एक True है?"।
In this page:
Syntax
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
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. #}
आम गलतियां
- 2-D arrays पर Python का any और all इस्तेमाल करना
- यह भूल जाना कि non-zero True है
- एक 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: