Numpy array မုဒ် (ဥပမာများဖြင့်) တွက်ချက်နည်း
NumPy array ၏မုဒ်ကိုရှာရန် အောက်ပါအခြေခံအထားအသိုကိုသုံးနိုင်သည်။
#find unique values in array along with their counts
vals, counts = np. unique (array_name, return_counts= True )
#find fashion
mode_value = np. argwhere (counts == np. max (counts))
မုဒ် သည် ဇယားတစ်ခုတွင် အများဆုံးတွေ့ရသည့် တန်ဖိုးဖြစ်သည်ကို သတိရပါ။
array တစ်ခုတွင် တစ်ခု သို့မဟုတ် တစ်ခုထက်ပိုသော မုဒ်များ ရှိနိုင်သည်ကို သတိပြုပါ။
အောက်ပါဥပမာများသည် ဤ syntax ကိုလက်တွေ့တွင်မည်သို့အသုံးပြုရမည်ကိုပြသထားသည်။
ဥပမာ 1- NumPy array မုဒ်ကို တစ်ခုတည်းမုဒ်ဖြင့် တွက်ချက်ခြင်း။
မုဒ်တစ်ခုသာပါရှိသော NumPy အခင်းအကျင်း၏မုဒ်ကို အောက်ပါကုဒ်တွင် မည်သို့ရှာဖွေရမည်ကို ပြသသည်-
import numpy as np #create NumPy array of values with only one mode x = np. array ([2, 2, 2, 3, 4, 4, 5, 5, 5, 5, 7]) #find unique values in array along with their counts vals, counts = np. unique (x, return_counts= True ) #find fashion mode_value = np. argwhere (counts == np. max (counts)) #print list of modes print (vals[mode_value] .flatten (). tolist ()) [5] #find how often mode occurs print (np. max (counts)) 4
output မှ mode သည် 5 ဖြစ်ပြီး NumPy array တွင် 4 ကြိမ်ဖြစ်ပေါ်သည်ကိုတွေ့နိုင်သည်။
ဥပမာ 2- NumPy အခင်းအကျင်းကို မုဒ်များစွာဖြင့် တွက်ချက်နည်း
အောက်ပါကုဒ်သည် မုဒ်များစွာရှိသည့် NumPy အခင်းအကျင်း၏မုဒ်ကို မည်သို့ရှာဖွေရမည်ကို ပြသသည်-
import numpy as np #create NumPy array of values with multiple modes x = np. array ([2, 2, 2, 3, 4, 4, 4, 5, 5, 5, 7]) #find unique values in array along with their counts vals, counts = np. unique (x, return_counts= True ) #find fashion mode_value = np. argwhere (counts == np. max (counts)) #print list of modes print (vals[mode_value] .flatten (). tolist ()) [2, 4, 5] #find how often mode occurs print (np. max (counts)) 3
output မှ၊ ဤ NumPy array တွင် မုဒ်သုံးမျိုးရှိသည်- 2၊ 4 နှင့် 5 ကိုတွေ့နိုင်သည်။
ဤတန်ဖိုးများတစ်ခုစီသည် ဇယားတွင် 3 ကြိမ်ပေါ်လာသည်ကိုလည်း ကျွန်ုပ်တို့တွေ့မြင်နိုင်ပါသည်။
ထပ်လောင်းအရင်းအမြစ်များ
အောက်ဖော်ပြပါ သင်ခန်းစာများသည် NumPy တွင် အခြားသော ဘုံလုပ်ဆောင်ချက်များကို မည်သို့လုပ်ဆောင်ရမည်ကို ရှင်းပြသည်-
လုပ်ဆောင်ချက်တစ်ခုကို NumPy အခင်းအကျင်းသို့ မည်သို့မြေပုံဆွဲမည်နည်း။
NumPy array တွင် တန်ဖိုးအညွှန်းကိန်းကို မည်သို့ရှာရမည်နည်း။
NumPy ကို အသုံးပြု၍ vector တစ်ခု၏ ပြင်းအား တွက်ချက်နည်း