Skip to content
Learn Netverks

Lesson

Step 7/36 19% through track

numpy-dtypes

NumPy dtypes

Last reviewed Jun 1, 2026 Content v20260601
Track mode
server_script
Means
Server runner
Reading
~1 min
Level
beginner

This lesson

This lesson teaches NumPy dtypes: NumPy ndarray operations, vectorization, and numerical patterns used across the Python scientific stack.

Wrong dtypes waste memory and break joins—int vs float vs datetime must be deliberate.

You will apply NumPy dtypes in contexts like: Notebooks, feature engineering pipelines, and custom numerical code.

Read the narrative, run `import numpy as np` snippets in the playground (install NumPy with pip if the runner lacks it), tweak shapes and dtypes, and complete MCQs.

When you can explain the previous lesson's ideas in your own words.

Every ndarray element has a fixed dtype (data type). Dtypes control memory size, precision, and which operations are valid.

Common dtypes

  • int8/int16/int32/int64 — signed integers
  • float32/float64 — IEEE floats (default float is usually float64)
  • bool_ — True/False
  • object — Python object references (slow, avoid when possible)

Casting and itemsize

import numpy as np
a = np.array([1, 2, 3], dtype=np.float32)
print(a.dtype, a.itemsize)  # 4 bytes per element

Type promotion

Operations between dtypes promote to a common type—mixing int and float yields float. Explicit .astype() controls conversions; watch for truncation when casting float to int.

Important interview questions and answers

  1. Q: float32 vs float64?
    A: float32 uses half the memory; float64 has more precision—ML often uses float32 on GPU.
  2. Q: object dtype?
    A: Stores pointers to Python objects—breaks vectorization speed benefits.

Self-check

  1. How many bytes per float64 element?
  2. What method converts an array to a different dtype?

Pitfall: Casting float to int truncates—use np.round first if needed.

Interview prep

float32 vs float64?

float32 half memory; float64 more precision—ML often uses float32 on GPU.

astype?

Casts array to new dtype—watch truncation float→int.

Interview tip Lesson completion confidence

Can you explain this lesson in 30 seconds without reading notes?

Not saved yet.

Playground

Runs on the configured server runner (dev: npm run runner with LEARNING_RUNNER_ENABLED=true). Output appears below the editor.

Check yourself

Multiple choice — immediate feedback.

Discussion

Past discussion is visible to everyone. Only logged-in users can post comments and replies.

Starter discussion topics

  • int64 vs float64?
  • astype copy?

Sign up or log in to post comments and sync lesson progress across devices.

No discussion yet. Be the first to ask a question.

Jump