NumPy မှာ data တွေကိုတွက်ချင်ရင် အရင်ဆုံး array တည်ဆောက်ရပါတယ်။ Array တည်ဆောက်နည်းများစွာရှိပြီး အသုံးအများဆုံးတွေက np.array(), np.zeros(), np.ones(), np.arange(), np.linspace() တို့ပါ။ ဘယ် function ကိုသုံးမလဲဆိုတာက data ကို ဘယ်လိုစတင်ချင်လဲပေါ်မူတည်ပါတယ်။
import numpy as np
# Create an array from an existing list
prices = np.array([1200, 1500, 1800, 2100])
print("Prices:", prices)
# Create a 2 rows x 3 columns array filled with zeros
empty_table = np.zeros((2, 3))
print("
Empty table:
", empty_table)
# Create values from 0 to 8, step by 2
steps = np.arange(0, 10, 2)
print("
Steps:", steps)
# Create 5 evenly spaced values between 0 and 1
percent = np.linspace(0, 1, 5)
print("
Percent points:", percent)np.array() က ရှိပြီးသား list ကို array ပြောင်းပေးပါတယ်။ np.zeros((2, 3)) က row 2 ခု၊ column 3 ခုပါတဲ့ zero table တစ်ခုလုပ်ပေးပါတယ်။ np.arange(0, 10, 2) မှာ stop value ဖြစ်တဲ့ 10 မပါဝင်တာကို သတိထားပါ။ np.linspace(0, 1, 5) က 0 နဲ့ 1 ကြားကို ညီမျှတဲ့ point 5 ခုခွဲပေးတာပါ။
Prices: [1200 1500 1800 2100] Empty table: [[0. 0. 0.] [0. 0. 0.]] Steps: [0 2 4 6 8] Percent points: [0. 0.25 0.5 0.75 1. ]Info
shape ကိုရေးတဲ့အခါ (rows, columns) ပုံစံ tuple နဲ့ရေးရပါတယ်။ np.zeros(2, 3) လို့ရေးရင် မျှော်လင့်သလိုမဟုတ်နိုင်ပါ။