Element-wise Arithmetic ऑपरेशन्स
+ - * / जैसे Operators automatically same position पर हर pair of elements पर apply होते हैं।
In this page:
Syntax
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
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. #}
आम गलतियां
- यह उम्मीद करना कि * matrix multiplication करेगा
- incompatible shapes वाले arrays combine करना
- 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: