Shape, Size und dtype
Die Struktur eines Arrays verstehen.
Shape, Size und dtype ist eine kostenlose Data Science Academy-Lektion auf CoddyKit. Dies ist Lektion 2 von 4. Du kannst die komplette Lektion unten kostenlos lesen – dann übst du sie direkt im Browser mit einem integrierten Code-Editor und einem KI-Tutor rund um die Uhr. Sie ist Teil des Data Science Academy-Lernpfads, und dein Fortschritt wird über Web und CoddyKit-App synchronisiert. Der Data Science Academy-Kurs umfasst insgesamt 4 Lektionen.
Teile dieser Lektion wurden noch nicht übersetzt und werden auf Englisch angezeigt.
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. 🎉
Häufig gestellte Fragen
Ist die Lektion „Shape, Size und dtype“ kostenlos?
Ja — der vollständige Text von „Shape, Size und dtype“ ist hier im Web kostenlos zu lesen. Um sie interaktiv zu üben (integrierter Code-Editor und 24/7 KI-Tutor) und den Rest des Data Science Academy-Kurses freizuschalten, upgrade auf CoddyKit PRO. Der Data Science Academy-Kurs umfasst insgesamt 4 Lektionen.
Was lerne ich in „Shape, Size und dtype“?
Die Struktur eines Arrays verstehen. Du übst Data Science Academy mit praktischem Code, den du direkt im Browser ausführst, und ein 24/7 KI-Tutor beantwortet deine Fragen während du die Lektion bearbeitest.
Brauche ich Erfahrung, um Data Science Academy zu starten?
Keine Vorkenntnisse erforderlich. Data Science Academy auf CoddyKit ist für Anfänger bis fortgeschrittene Lernende strukturiert, sodass du hier starten oder von Anfang an beginnen und in deinem eigenen Tempo voranschreiten kannst. Dies ist Lektion 2 von 4.
Wie lange dauert die Lektion „Shape, Size und dtype“?
Die meisten CoddyKit-Lektionen dauern etwa 5–10 Minuten. Jede ist kompakt und interaktiv, sodass du stetig Fortschritte machst und genau dort weitermachst, wo du aufgehört hast – im Web und in der App.
Kann ich in dieser Data Science Academy-Lektion Code schreiben und ausführen?
Ja. Jede Data Science Academy-Lektion enthält einen integrierten Code-Editor, sodass du echten Code direkt in deinem Browser schreibst und ausführst und sofort KI-Feedback erhältst — ohne lokale Einrichtung erforderlich.
Alle Lektionen in diesem Kurs
- Von der Python-Liste zum ndarray
- Shape, Size und dtype
- Vektorisierte Mathematik ohne Schleifen
- Arrays indizieren und Slices erstellen