Shape, size i dtype
Poznaj budowę tablicy.
Shape, size i dtype to bezpłatna lekcja Data Science Academy na CoddyKit. To lekcja 2 z 4. Możesz przeczytać całą lekcję poniżej za darmo — a potem ćwiczyć ją interaktywnie w przeglądarce z wbudowanym edytorem kodu i tutorem AI dostępnym 24/7. To część ścieżki edukacyjnej Data Science Academy, a Twój postęp synchronizuje się między webem a aplikacją CoddyKit. Kurs Data Science Academy zawiera 4 lekcji w sumie.
Części tej lekcji nie zostały jeszcze przetłumaczone i są wyświetlane po angielsku.
Read the Array's Anatomy
Every array carries metadata about itself. Three labels tell you almost everything: its shape, its size, and its dtype. Let's read each one. 🔍
Shape: Rows and Columns
The shape is a tuple of dimension lengths. A 3-by-4 grid reports (3, 4): three rows down, four columns across.
a = np.zeros((3, 4))
a.shape # (3, 4)Shape Tells You the Layout
Shape is your first sanity check. If a model expects (100, 5) and you hand it (5, 100), the shape mismatch is where bugs hide.
ndim: How Many Dimensions
The ndim attribute counts dimensions. A flat row is 1, a table is 2, a stack of tables is 3. It is just the length of the shape.
a.ndim # 2Size: Total Element Count
The size is the total number of elements, the product of every shape value. A (3, 4) array has a size of 12.
a.size # 12dtype: The One Shared Type
The dtype names the single type all elements share, like int64 or float64. It controls both precision and memory use.
np.array([1, 2, 3]).dtype # int64Choose Your dtype on Purpose
You can set the type yourself with the dtype argument. Use a smaller type like int32 to save memory on huge arrays.
np.array([1, 2, 3], dtype='int32')dtype Affects Precision
float32 holds fewer decimals than float64. Tiny rounding gaps add up, so pick the type your numbers actually need.
Convert With astype
Already have an array? astype returns a copy in a new type, handy for turning floats into clean integers.
f = np.array([1.0, 2.0])
f.astype('int64')itemsize: Bytes Per Element
The itemsize tells you bytes per element. Multiply it by size to estimate the array's total memory footprint.
a.itemsize # 8 for float64Inspect Before You Compute
Checking shape and dtype first saves hours. They reveal mismatched data and wrong types before a calculation quietly goes wrong. ✅
Quick Check
Let's test your read of an array's shape.
Recap
You can now read an array at a glance: shape for layout, ndim and size for counts, and dtype for the shared type. These four checks catch most bugs early. 🎉
Często zadawane pytania
Czy lekcja „Shape, size i dtype” jest bezpłatna?
Tak — pełny tekst „Shape, size i dtype” jest dostępny za darmo tutaj w sieci. Aby ćwiczyć ją interaktywnie (wbudowany edytor kodu i tutor AI dostępny 24/7) i odblokować resztę kursu Data Science Academy, przejdź na CoddyKit PRO. Kurs Data Science Academy zawiera 4 lekcji w sumie.
Co nauczysz się w „Shape, size i dtype”?
Poznaj budowę tablicy. Ćwiczysz Data Science Academy z praktycznym kodem, który uruchamiasz bezpośrednio w przeglądarce, a tutor AI dostępny 24/7 odpowiada na Twoje pytania podczas pracy nad lekcją.
Czy potrzebuję doświadczenia, aby zacząć Data Science Academy?
Nie wymagamy żadnego doświadczenia. Data Science Academy w CoddyKit jest strukturyzowany dla początkujących i zaawansowanych użytkowników, więc możesz zacząć tutaj lub od początku i uczyć się w swoim tempie. To lekcja 2 z 4.
Ile czasu zajmuje lekcja „Shape, size i dtype”?
Większość lekcji CoddyKit trwa około 5–10 minut. Każda lekcja to mały, interaktywny krok, dzięki czemu robisz systematyczne postępy i zawsze wracasz dokładnie do tego samego miejsca — na webie i w aplikacji.
Czy mogę pisać i uruchamiać kod w tej lekcji Data Science Academy?
Tak. Każda lekcja Data Science Academy zawiera wbudowany edytor kodu, więc piszesz i uruchamiasz prawdziwy kod bezpośrednio w przeglądarce i od razu otrzymujesz sprzężenie zwrotne od AI — bez konfiguracji na komputerze.
Wszystkie lekcje w tym kursie
- Od listy Pythona do ndarray
- Shape, size i dtype
- Wektoryzowana matematyka bez pętli
- Indeksowanie i wycinanie tablic