Skip to content
Learn Netverks

Lesson

Step 33/36 92% through track

numpy-in-ml-preview

NumPy in machine learning preview

Last reviewed May 28, 2026 Content v20260528
Track mode
server_script
Means
Server runner
Reading
~1 min
Level
intermediate

This lesson

This lesson teaches NumPy in machine learning preview: NumPy ndarray operations, vectorization, and numerical patterns used across the Python scientific stack.

Teams apply NumPy in machine learning preview in every serious NumPy project—skipping it leaves blind spots in analysis and reviews.

You will apply NumPy in machine learning preview in contexts like: scikit-learn, PyTorch, and TensorFlow tensor operations.

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.

Toward the end—consolidate before Pandas, SciPy tracks, and interview prep.

ML libraries expect feature matrices as 2D float ndarrays: rows = samples, columns = features. Labels are 1D arrays. NumPy is the lingua franca before tensors on GPU.

Shape conventions

  • X.shape == (n_samples, n_features)
  • y.shape == (n_samples,) for classification/regression
  • Images: (n_samples, height, width, channels)

Train matrix example

import numpy as np
X = np.array([[1, 0], [0, 1], [1, 1]], dtype=float)
y = np.array([0, 0, 1])
print(X.shape, y.shape)

From NumPy to frameworks

PyTorch torch.from_numpy shares memory when possible. TensorFlow and JAX wrap similar array concepts with autograd and device placement.

Important interview questions and answers

  1. Q: Why float64 vs float32 in ML?
    A: Training often float32 for speed; NumPy defaults float64—cast before GPU transfer.
  2. Q: Standardize features?
    A: Subtract mean, divide std—fit on train only per data science hygiene.

Self-check

  1. Expected shape of sklearn feature matrix X?
  2. What dtype is common for neural net training?

Tip: Keep X as (n_samples, n_features) float arrays.

Interview prep

X shape?

(n_samples, n_features) float matrix.

Standardize?

Fit mean/std on train only—apply to val/test.

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

  • sklearn array input?
  • Torch tensor bridge?

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