An warware: ginshiƙin goge lambobi na Python

A cikin wannan labarin, za mu tattauna game da yaren shirye-shiryen Python, musamman mai da hankali kan ɗakin karatu na NumPy da yadda ake share shafi ta amfani da wannan ɗakin karatu. Python harshe ne na shirye-shirye iri-iri da ake amfani da shi don dalilai daban-daban, gami da haɓaka yanar gizo, nazarin bayanai, basirar wucin gadi da ƙari. Ɗaya daga cikin mahimman abubuwan da ke cikin shaharar Python shi ne ɗakunan karatu da yawa, waɗanda ke sa tsarin codeing ya fi dacewa da sauƙin sarrafawa. NumPy ɗaya ne irin wannan ɗakin karatu, wanda aka ƙera musamman don aiki tare da manyan, tsararraki masu girma dabam da matrices na bayanan ƙididdiga. A fagen sarrafa bayanai, yana da mahimmanci a san yadda ake share ginshiƙai daga tsararru, saboda wannan mataki ne na gama-gari a cikin ayyukan aiki da yawa.

Laburaren NumPy yana ba da aikin abokantaka mai amfani da ake kira 'share' don cimma wannan aikin. Aikin numpy.delete() yana da ikon cire abubuwa a cikin tsararru, tare da ƙayyadadden axis. Wannan ya sauƙaƙa mana don share shafi daga tsararrun 2D ko matrix.

Don farawa, bari mu shigo da ɗakin karatu na NumPy kuma mu ƙirƙiri samfurin tsararrun 2D:

import numpy as np

array = np.array([[1, 2, 3], [4, 5, 6], [7, 8, 9]])
print("Original array:")
print(array)

Yanzu, za mu yi amfani da aikin `np.delete()` don share takamaiman shafi daga tsararrun mu na 2D:

# Deleting the second column (index 1)
array_modified = np.delete(array, 1, axis=1)
print("nArray with the second column deleted:")
print(array_modified)

Bayyana aikin np.delete().

Aikin np.delete() yana ɗaukar manyan gardama guda uku: tsarin shigar da bayanai, fihirisa na element ko ginshiƙin da za a goge, da axis ɗin da za a goge. Ma'aunin axis yana da mahimmanci a wannan yanayin tunda muna son share ginshiƙi, ba kawai wani abu ba. Ta hanyar saita axis = 1, muna gaya wa aikin don sharewa tare da axis na shafi. Idan za mu saita axis=0, aikin zai goge tare da layin layi.

Lura cewa aikin np.delete() baya canza ainihin tsararru a wurin. Madadin haka, yana dawo da sabon tsararrun tsararru, wanda ke da mahimmanci lokacin da kuke son kiyaye ainihin bayanan cikin aikin ku.

Kewaya ɗakin karatu na NumPy

Laburaren NumPy yana da dabaru da ayyuka iri-iri don sarrafa manyan, tsararraki masu girma dabam da matrices na bayanan lamba. Shahararrun ayyuka sun haɗa da 'sake siffa', 'concatenate', 'raga', da ƙari mai yawa. NumPy shine ainihin kunshin don lissafin lissafi da kimiyya tare da Python saboda ingantacciyar tsarin bayanai da sauƙin amfani.

Fahimtar hanyar NumPy na sarrafa tsararraki da sarrafa bayanai muhimmin mataki ne ga kowane masanin kimiyyar bayanai ko mai sha'awar koyon injin. Bugu da ƙari, fahimtar manufar sharewa da gyaggyarawa ginshiƙai a cikin tsararrun NumPy na iya zama taimako don sarrafa manyan bayanai kafin aiwatarwa, saboda share ginshiƙan da ba su da mahimmanci ko waɗanda ba dole ba na iya haɓaka lokacin sarrafawa da sauƙaƙe bayanan.

Shafi posts:

Leave a Comment