NumPy babban ษakin karatu ne mai buษewa a cikin Python wanda ke sauฦaฦe ฦididdige ฦididdigewa ta hanyar samar da ฦaฦฦarfan tsarin ayyuka da kayan aiki don aiwatar da ayyukan lissafi akan manyan tsararru da matrices masu girma dabam. Daga cikin ayyuka daban-daban da ake da su a cikin NumPy, ษayan ฦarancin sanannun amma fasali mai fa'ida shine ikon cire jagora da/ko sifilin sifili daga tsararraki. Wannan fasalin zai iya zama mai taimako musamman a duniyar salon, inda daidaito da inganci ke da mahimmanci wajen ฦira da gina riguna, tsarin launi, da alamu.
A cikin wannan labarin, za mu nutse cikin cikakken misali na yadda ake amfani da NumPy's datsa_zeros aiki tare da takamaiman mayar da hankali kan datsa ='b' siga. Bugu da ฦari, za mu tattauna aikin lambar kuma za mu ba da cikakken bayani game da ษakunan karatu da ayyukan da ke cikin matsala.
Da farko, bari mu yi la'akari da matsalar da muke son warwarewa. A ce kuna da ma'aunin ma'aunin tufa, inda kowane kashi yana wakiltar takamaiman tsayi ko faษi cikin santimita. ฦimar da ke cikin tsararrun ฦila ta ฦunshi sifili masu jagora da masu bin diddigi saboda rashin daidaiton aunawa ko kuskuren ษan adam. Manufar ita ce a cire waษannan sifilai marasa mahimmanci daga ma'auni don ฦirฦirar ingantaccen tsarin bayanai.
Mu dauki wannan tsararru a matsayin misali:
import numpy as np measurements = np.array([0, 0, 25, 42, 55, 0, 60, 0])
Yanzu, muna so mu cire duka biyun jagora da sifili ta amfani da aikin trim_zeros da aka yi amfani da shi tare da sigar datsa ='b'. Maganin wannan matsala shine kamar haka.
trimmed_measurements = np.trim_zeros(measurements, trim='b') print(trimmed_measurements)
Da fitarwa zai zama:
array([25, 42, 55, 0, 60])
Fahimtar Code
Bari mu zurfafa zurfafa cikin yadda lambar ke aiki don ฦarin fahimtar abubuwan da ke cikin tushe da ayyukan da ke ciki. Abu na farko da muka yi shi ne shigo da ษakin karatu na NumPy da ฦirฦirar tsarar ma'aunin misali.
Bayan haka, mun yi amfani da aikin trim_zeros tare da sigar 'b'. Ma'aunin datsa yana ษaukar ษaya daga cikin ฦima guda uku masu yiwuwa: 'f' (don cire sifilai masu jagora), 'b' (don cire sifilai masu biyo baya), da 'fb' (don cire duka biyun jagora da sifili). A cikin yanayinmu, mun zaษi 'b' saboda muna son cire sifilin da ke biyo baya kawai.
A ฦarshe, bayan aiwatar da aikin trim_zeros, yana sabunta tsararrun ma'auni ba tare da sifili masu biyo baya ba kuma yana buga tsararrun da aka gyara.
Ayyukan NumPy da Laburaren da ke da alaฦa
Yanzu da muka fahimci matsalar da muka warware da kuma yadda lambar ke aiki, bari mu ษan duba ayyukan NumPy da ษakunan karatu masu alaฦa waษanda ke da alaฦa da aikin trim_zeros.
- nupy.asarray(): Wannan aikin yana kama da numpy.array(), amma yana da ฦดan zaษuษษuka kuma baya yin kwafin bayanan shigarwa idan bayanan shigarwa ya riga ya zama ndarray ko pandas.Series.
- numpy.concatenate(): Yana ba ka damar haษa nau'i biyu ko fiye tare da axis data kasance.
- nupy.delete(): Ana amfani da wannan aikin don share abubuwa daga tsararru tare da ฦayyadadden axis bisa ga fihirisar element.
Baya ga ษakin karatu na NumPy, akwai wasu ษakunan karatu na Python waษanda za su iya taimakawa wajen magance irin waษannan matsalolin, kamar Pandas don sarrafa bayanai da Scikit-koyi don algorithms koyon injin.
Ta wannan misalin da bayanin, muna fatan kun sami kyakkyawar fahimtar yadda ake amfani da aikin NumPy's trim_zeros tare da ma'aunin 'b', da kuma yadda za'a iya amfani da shi a fagen sarrafa bayanan salo. Ta hanyar ฦware waษannan mahimman shirye-shiryen Python da dabarun SEO, zaku iya haษaka ฦwarewar coding ษin ku kuma ฦirฦirar ingantacciyar mafita, ingantacciyar mafita ga ษimbin matsaloli.