0Pricing
Data Science Academy · Lesson

Shape, Size, and dtype

Reading the anatomy of an array.

Shape, Size, and dtype is a free Data Science Academy lesson on CoddyKit — lesson 2 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the Data Science Academy learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.

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  # 2

Size: 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  # 12

dtype: 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  # int64

Choose 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 float64

Inspect 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. 🎉

Frequently asked questions

Is the “Shape, Size, and dtype” lesson free?

Yes — the full text of “Shape, Size, and dtype” is free to read here on the web, and the Data Science Academy course includes 4 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the Data Science Academy course, upgrade to CoddyKit PRO.

What will I learn in “Shape, Size, and dtype”?

Reading the anatomy of an array. You practise Data Science Academy with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.

Do I need any experience to start Data Science Academy?

No prior experience is required. Data Science Academy on CoddyKit is structured for beginners through advanced learners; this is — lesson 2 of 4, so you can start here or from the beginning and move at your own pace.

How long does the “Shape, Size, and dtype” lesson take?

Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.

Can I write and run code in this Data Science Academy lesson?

Yes. Every Data Science Academy lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.

All lessons in this course

  1. From Python List to ndarray
  2. Shape, Size, and dtype
  3. Vectorized Math Without Loops
  4. Indexing and Slicing Arrays
← Back to Data Science Academy