An warware: cire akai-akai daga jeri

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.

Shafi posts:

Leave a Comment