NumPy arithmetic operations တွေက element-wise အလုပ်လုပ်ပါတယ်။ ဆိုလိုတာက array နှစ်ခုထဲက တူညီတဲ့ position မှာရှိတဲ့ element တွေကို တစ်စုံချင်းတွက်ပေးတာပါ။ Python loop မရေးဘဲ discount, tax, score adjustment, unit conversion စတာတွေကို အလွယ်တကူတွက်နိုင်ပါတယ်။
import numpy as np
price = np.array([1000, 1500, 2000])
tax = np.array([50, 75, 100])
print("Price + tax:", price + tax)
print("Price after 10% discount:", price * 0.9)
print("Price difference from 1500:", price - 1500)price + tax က position တူတဲ့ element တွေကိုပေါင်းပါတယ်။ price * 0.9 က price element တိုင်းကို 0.9 နဲ့မြှောက်ပြီး 10% discount ပြီးသားတန်ဖိုးကိုတွက်ပါတယ်။ Scalar number တစ်ခုနဲ့ array ကိုတွက်တဲ့အခါ scalar ကို element တိုင်းပေါ်သက်ရောက်စေပါတယ်။
Price + tax: [1050 1575 2100] Price after 10% discount: [ 900. 1350. 1800.] Price difference from 1500: [-500 0 500]Info
Array နှစ်ခုကို element-wise တွက်ချင်ရင် shape တူရတာများပါတယ်။ Shape မတူရင် broadcasting rule နဲ့ကိုက်မှသာတွက်လို့ရပါတယ်။