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

Arrays पर Comparison Operators

> < == से arrays compare करना True और False का एक array देता है, प्रति element एक answer।
Syntax
python
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

python
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. #}
आम गलतियां
  1. एक if statement के अंदर arrays पर == इस्तेमाल करना, जो एक ambiguity error raise करता है
  2. allclose की बजाय == से floats compare करना
  3. यह भूल जाना कि 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:

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.