Thuta Learning
ရှာဖွေရန်
IntermediateData & Databasesintermediate

Aggregations

စိတ်လျှော့ပါ။ ဒီခန်းကို စာအုပ်လိုမဟုတ်ဘဲ စကားပြောသလိုပဲ၊ နားလည်လွယ်အောင် ရှင်းပါမယ်။

Aggregation ဆိုတာ array ထဲက data အစုလိုက်ထဲကနေ single summary value သို့မဟုတ် row/column summary ကိုတွက်တာပါ။ sum, min, max, mean, median, std တို့က data analysis မှာအမြဲလိုလိုသုံးရတဲ့ tools တွေပါ။

python
import numpy as np

sales = np.array([
    [120, 135, 150],
    [160, 155, 180]
])

print("Total sales:", sales.sum())
print("Average sales:", sales.mean())
print("Highest sale:", sales.max())
print("Column totals:", sales.sum(axis=0))
print("Row totals:", sales.sum(axis=1))

sales.sum() က element အားလုံးကိုပေါင်းပါတယ်။ axis=0 ဆိုတာ column-wise တွက်တာဖြစ်ပြီး axis=1 ဆိုတာ row-wise တွက်တာပါ။ Row/column summary တွေလိုတဲ့အခါ axis ကိုနားလည်တာအရေးကြီးပါတယ်။

You should see
Total sales: 900 Average sales: 150.0 Highest sale: 180 Column totals: [280 290 330] Row totals: [405 495]

Info

Axis ကိုမှတ်ရခက်ရင် ဒီလိုစဉ်းစားပါ။ axis=0 က rows တွေကိုဖြတ်ပြီး column result ထုတ်တယ်။ axis=1 က columns တွေကိုဖြတ်ပြီး row result ထုတ်တယ်။

ဒီနေရာမှာ လူအများမှားတတ်တယ်

  • Row total လိုချင်ပြီး axis=0 သုံးမိရင် result က column total ဖြစ်သွားပါမယ်။ Output shape ကိုကြည့်ပြီး ကိုယ်လိုချင်တာဟုတ်/မဟုတ်စစ်ပါ။

လေ့ကျင့်ခန်း

ကျောင်းသားတစ်ယောက်ချင်းစီရဲ့ average, subject တစ်ခုချင်းစီရဲ့ average တွေတွက်တာမျိုးမှာ aggregation + axis က တော်တော်အသုံးဝင်ပါတယ်။

python
import numpy as np

exam_scores = np.array([
    [80, 75, 90],
    [88, 92, 85],
    [70, 78, 82]
])

student_average = exam_scores.mean(axis=1)
subject_average = exam_scores.mean(axis=0)

print("Student averages:", student_average)
print("Subject averages:", subject_average)

You'll know it worked when: Student averages: [81.66666667 88.33333333 76.66666667] Subject averages: [79.33333333 81.66666667 85.66666667]

Aggregations | Thuta Learning