Samu Girman Tensor a Python: Fahimtar Ra'ayi da Aiwatarwa
Tensors tsararraki ne masu girma dabam waษanda ake amfani da su sosai a fagage daban-daban kamar koyon injin, koyo mai zurfi, da hangen nesa na kwamfuta. Yawancin lokaci, yana zama mahimmanci don sanin girma ko siffar tensor don yin ayyuka kamar sake fasalin, watsa shirye-shirye, da sauransu. A cikin wannan labarin, za mu nutse cikin tsarin samun ma'auni na tensor ta amfani da Python, tare da bayanin mataki-mataki na lambar, da kuma bincika wasu ษakunan karatu da ayyuka masu dangantaka da ke taka muhimmiyar rawa wajen sarrafa tensor.
Don magance matsalar samun girman tensor, za mu yi amfani da mashahurin ษakin karatu Lambobi da ginannen aikin sa siffar. Don farawa, bari mu fara shigo da ษakin karatu na NumPy kuma mu ฦirฦiri samfurin tensor.
import numpy as np tensor = np.array([[[1, 2, 3], [4, 5, 6]], [[7, 8, 9], [10, 11, 12]]])
Yanzu da muke da tensor ษin mu, muna iya ฦoฦarin samun girman sa ta amfani da siffar sifa.
tensor_dimensions = tensor.shape print("Tensor dimensions:", tensor_dimensions)
Wannan snippet code zai fitar da mai zuwa:
โโ
Girman Tensor: (2, 2, 3)
โโ
Maษallin tensor_dimensions yanzu yana ฦunshe da ma'auni na tensor ษin mu a cikin tsarin tuple (2, 2, 3). Don ฦarin fahimtar sakamakon da aka samu, bari mu rarraba lambar mataki-mataki.
Laburaren NumPy
- Lambobi ษakin karatu ne mai ฦarfi na Python wanda ke ba da tallafi don aiki tare da manyan, tsararru da matrices masu girma dabam. Ya zo tare da tarin ayyukan lissafi don yin ayyuka akan waษannan tsararrun.
- Ya zama tushe na fakiti da dakunan karatu na kimiyya daban-daban, musamman a fagen koyon injina da tantance bayanai.
ฦirฦirar Tensor tare da NumPy
A cikin misalinmu, mun ฦirฦiri 3D tensor ta amfani da np.array aiki. Wannan aikin yana ษaukar jerin jeri (ko wasu sifofi masu kama da tsararru) azaman shigarwa kuma yana jujjuya shi zuwa tsararru mai girma dabam ko tensor.
tensor = np.array([[[1, 2, 3], [4, 5, 6]], [[7, 8, 9], [10, 11, 12]]])
Tensor ษin da aka ฦirฦira yana da siffar (2, 2, 3), inda girman farko ke wakiltar adadin jeri na gida, girma na biyu yana tsaye ga adadin lissafin ciki a kowane jeri na gida, kuma girma na uku yana nuna adadin abubuwan. a cikin kowane ciki list.
Amfani da Siffar Siffar
The siffar sifa da ke akwai a cikin NumPy yana taimaka mana samun girman tensor ษin mu ba tare da wata wahala ba.
tensor_dimensions = tensor.shape
tensor.siffa yana dawo da tuple mai wakiltar ma'auni na tensor a cikin tsari (dimension_1, dimension_2, โฆ, dimension_n).
A ฦarshe, samun ฦimar tensor a Python abu ne mai sauฦi da inganci, musamman tare da taimakon ษakin karatu na NumPy. Ta hanyar fahimtar sifa da kuma amfani da ayyuka daban-daban da aka gina, za mu iya magance matsaloli masu yawa da suka shafi tenors da girman su.