← Back to NumPy Course | Chapter 6: Math Operations | Lesson 1 of 7

Element-wise Arithmetic ऑपरेशन्स

+ - * / जैसे Operators automatically same position पर हर pair of elements पर apply होते हैं।

In this page:

  1. Element-Wise Arithmetic
Syntax
python
arr1 + arr2
arr1 - arr2
arr1 * arr2
arr1 / arr2
arr1 ** 2
arr * scalar

Element-Wise Arithmetic

Same shape के दो arrays के साथ, +, -, *, /, और ** element by element काम करते हैं। एक scalar के साथ, scalar हर element पर apply होता है। ध्यान दें कि * matrix multiplication नहीं है; यह matching elements multiply करता है।

Note: floor division के लिए // और remainders के लिए % इस्तेमाल करें, ये भी element-wise हैं।

उदाहरण: Element-wise arithmetic

python
import numpy as np

a = np.array([1, 2, 3])
b = np.array([10, 20, 30])
print(a + b)
print(b - a)
print(a * b)
print(b / a)
print(a ** 2)

# Output:
# [11 22 33]
# [ 9 18 27]
# [10 40 90]
# [10. 10. 10.]
# [1 4 9]
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. यह उम्मीद करना कि * matrix multiplication करेगा
  2. incompatible shapes वाले arrays combine करना
  3. Integer arrays और / silently floats produce करना
चैप्टर सारांश
  • Operators element-wise काम करते हैं
  • Scalars सारे elements पर apply होते हैं
  • * matrix product नहीं है
  • / हमेशा floats return करता है
🔒

Chapter Quiz — Complete all 7 topics to unlock

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