A cikin duniyar shirye-shirye, akwai lokuta da yawa da ake buฦatar yin wani aiki akan abubuwa da yawa a cikin jerin lokaci ษaya, maimakon yin shi ษaya ษaya. ฦaya daga cikin irin waษannan misalai na waษannan ayyuka a cikin shirye-shiryen Python na iya zama raguwa mai tsayi daga kowane nau'i na jeri. Irin wannan aiki ya zama ruwan dare wajen sarrafa bayanai, kuma Python, harshe mai inganci da inganci, yana da ingantattun hanyoyin gudanar da irin waษannan ayyuka.
Python, harshen da aka fassara, babban matakin, babban maฦasudin shirye-shirye, ya zo tare da ษimbin ginanniyar hanyoyin ginawa da waje da ษakunan karatu don gudanar da ayyuka daban-daban akan bayanan. Don cire dindindin daga jeri, Python yana ba da hanyoyi da yawa. Waษannan na iya kewayo daga amfani da asali don madauki zuwa aiwatar da hanyoyin ci gaba daga ษakunan karatu na waje kamar NumPy.
# Initial List A = [12, 8, 6, 10] # Constant to subtract c = 5 # Using list comprehension B = [i - c for i in A]
Rubutun lambar da ke sama ta fara ฦirฦirar jeri, `A`, da akai-akai, `c`, don cirewa daga kowane kashi na `A`. Sannan, kalmar Python gama gari, ana amfani da fahimtar lissafi don cire `c' daga kowane kashi a cikin `A`.
Binciken Fahimtar Lissafi
Lissafin fahimta samar da takaitacciyar hanya don ฦirฦirar jeri bisa lissafin da ke akwai. A cikin yanayinmu, muna amfani da shi don ฦirฦirar sabon jeri wanda shine sakamakon aiki (ragi) da aka yi amfani da shi ga kowane memba na lissafin da ke akwai.
Rubutun kalma yana kama da kafa madauki, amma duk akan layi daya ne kuma yana samar da sabon jeri. Mafi mahimmancin tsari tare da masu canjin mu shine [bayanin (a) don a cikin A]. A bayyane yake cewa wannan yana ษaukar kowane nau'in 'a' a cikin jerin 'A' kuma ya wuce shi zuwa 'bayani (a)'.
Amma kuma za mu iya ฦara sharadi zuwa fahimtar lissafin, mu sa shi ya zama kamar haษin madauki da kuma idan sanarwa.
Amfani da NumPy don Ayyuka akan Lissafi
Lokacin mu'amala da manyan bayanai, yin amfani da ginanniyar hanyoyin Python na iya zama mara inganci. A irin waษannan lokuta, Python yana ba da ษakunan karatu na waje kamar Lambobi waษanda aka kera musamman don sarrafa manyan bayanai cikin ingantaccen tsari.
import numpy as np # Using numpy A = np.array(A) B = A - c
Laburaren NumPy yana ba da nau'in abu da ake kira tsararru wanda ya fi dacewa kuma ya dace don nazarin bayanai fiye da jerin Python na yau da kullun. Arrays a cikin NumPy na iya yin duk daidaitattun ayyuka kamar ฦari, ragi, ninkawa da sauransu akan duk abubuwa lokaci ษaya, wanda zai iya adana lokacin coding da lokacin aiwatarwa.