Universal Functions သို့မဟုတ် ufuncs ဆိုတာ array ထဲက element တိုင်းကို function တစ်ခုတည်းနဲ့မြန်မြန်တွက်ပေးတဲ့ NumPy functions တွေပါ။ ဥပမာ np.sqrt(), np.round(), np.sin(), np.exp(), np.log() စတာတွေဖြစ်ပါတယ်။
import numpy as np
values = np.array([1, 4, 9, 16])
print("Square root:", np.sqrt(values))
print("Power 2:", np.power(values, 2))
print("Rounded average:", np.round(values.mean(), 2))np.sqrt(values) က element တိုင်းရဲ့ square root ကိုတွက်ပါတယ်။ np.power(values, 2) က element တိုင်းကို power 2 တင်ပါတယ်။ values.mean() က average ကိုတွက်ပြီး np.round(..., 2) က decimal 2 နေရာအထိ round လုပ်ပါတယ်။
Square root: [1. 2. 3. 4.] Power 2: [ 1 16 81 256] Rounded average: 7.5Info
ufuncs တွေကိုသုံးရင် loop ရေးတာထက် code ပိုတိုပြီး performance ပိုကောင်းလေ့ရှိပါတယ်။ Data များလာတဲ့အခါ ဒီကွာခြားချက်က သိသာလာပါတယ်။