Skip to content
Learn Netverks

Lesson

Step 18/36 50% through track

dot-matmul

Dot product and matmul

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

This lesson

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

ML feature matrices and weights are ndarray algebra—shape errors explode in training loops.

You will apply Dot product and matmul 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.

Matrix multiplication uses @ (Python 3.5+) or np.dot. For 2D arrays, A @ B computes standard matrix product; 1D cases follow inner-product rules.

2D matrix multiply

import numpy as np
A = np.array([[1, 2], [3, 4]])
B = np.array([[5, 6], [7, 8]])
print(A @ B)

Inner vs outer

  • np.dot(a, b) — inner product for 1D; matrix product for 2D
  • np.matmul / @ — strict linear algebra rules
  • np.outer(a, b) — rank-1 outer product

Shape requirement

For (m, n) @ (n, p) inner dimensions must match. Mismatch raises clear ValueError—check shapes first.

Important interview questions and answers

  1. Q: A * B vs A @ B?
    A: Star is element-wise; @ is matrix multiply (sum of products across inner axis).
  2. Q: Why @ over np.dot?
    A: @ is readable and preferred for matrix algebra in modern code.

Self-check

  1. Multiply 2×3 matrix by 3×2 matrix—result shape?
  2. Compute dot product of two 1D vectors.

Tip: Verify inner dimensions match before @.

Interview prep

Shape rule?

(m,n) @ (n,p) → (m,p).

outer?

Rank-1 outer product of two vectors.

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

  • dot vs matmul?
  • 2D vs 1D dot?

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