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

Array Attributes

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

Array တစ်ခုကို ကောင်းကောင်းကိုင်တွယ်ချင်ရင် သူ့ရဲ့ structure ကိုသိဖို့လိုပါတယ်။ ndim, shape, size, dtype ဆိုတဲ့ attributes တွေက array ထဲမှာ dimension ဘယ်နှစ်ခုရှိလဲ၊ row/column ဘယ်လောက်လဲ၊ element ဘယ်နှစ်ခုလဲ၊ data type ဘာလဲဆိုတာ ပြောပြပေးပါတယ်။

python
import numpy as np

scores = np.array([[80, 75, 90], [88, 92, 85]])

print("Dimensions:", scores.ndim)
print("Shape:", scores.shape)
print("Total items:", scores.size)
print("Data type:", scores.dtype)

ဒီ array မှာ row 2 ခု၊ column 3 ခုရှိပါတယ်။ scores.ndim က 2-D array ဖြစ်ကြောင်းပြောပါတယ်။ scores.shape က (2, 3) ဆိုပြီး row/column အရေအတွက်ကိုပြပါတယ်။ size က element စုစုပေါင်း 6 ခုရှိကြောင်းပြပါတယ်။

You should see
Dimensions: 2 Shape: (2, 3) Total items: 6 Data type: int64

Info

shape ကိုနားလည်တာက NumPy ရဲ့အရေးကြီးဆုံးအခြေခံတွေထဲကတစ်ခုပါ။ Broadcasting, reshaping, matrix multiplication တွေမှာ shape မကိုက်ရင် error တက်လေ့ရှိပါတယ်။

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

  • Different operating systems မှာ dtype output က int64 သို့မဟုတ် int32 ဖြစ်နိုင်ပါတယ်။ ဒါက ပုံမှန်ပါ။

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

Debug လုပ်တဲ့အခါ “ဘာလို့ calculation မရတာလဲ” ဆိုရင် ပထမဆုံး shape ကို print ထုတ်စစ်တာက အချိန်အများကြီးသက်သာစေပါတယ်။

You'll know it worked when:

Array Attributes | Thuta Learning