Arrays पर Comparison Operators
> < == से arrays compare करना True और False का एक array देता है, प्रति element एक answer।
In this page:
Syntax
arr == value
arr != value
arr > value
arr <= value
Arrays पर Comparison Operators
Comparison operators (==, !=, <, <=, >, >=) element-wise apply होते हैं और boolean arrays return करते हैं। matches count करने के लिए इन masks को sum किया जा सकता है, क्योंकि True 1 count होता है। पूरे arrays की equality compare करने के लिए np.array_equal या np.allclose इस्तेमाल करें।
Note:
(a > 3).sum() count करता है कितने elements 3 से बड़े हैं।
उदाहरण: Comparison operators on arrays
import numpy as np
a = np.array([1, 5, 3, 8])
print(a > 3)
print((a > 3).sum())
print(a == np.array([1, 0, 3, 0]))
print(np.array_equal(a, a.copy()))
# Output:
# [False True False True]
# 2
# [ True False True 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. #}
आम गलतियां
- एक if statement के अंदर arrays पर == इस्तेमाल करना, जो एक ambiguity error raise करता है
- allclose की बजाय == से floats compare करना
- यह भूल जाना कि result एक array है
चैप्टर सारांश
- Comparisons boolean arrays return करते हैं
- sum होने पर True 1 count होता है
- पूरे-array equality के लिए array_equal इस्तेमाल करें
- floats के लिए allclose इस्तेमाल करें
🔒
Chapter Quiz — Complete all 6 topics to unlock
0/6 topics done
Complete these topics first: