0Pricing
Deep Learning Academy · Lesson

Matrix Multiply with matmul and @

The dot products behind every layer.

Matrix Multiply with matmul and @ is a free Deep Learning Academy lesson on CoddyKit — lesson 3 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 Deep Learning Academy learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.

Beyond Elementwise

Multiplying tensors with the star sign is elementwise. Matrix multiplication is different: it mixes rows and columns into weighted sums.

Dot Products in Bulk

Each output entry of a matrix multiply is a dot product: one row of the left matrix paired with one column of the right matrix.

The Inner Dimensions Must Match

To multiply shapes (m, k) and (k, n), the inner k must agree. The result is (m, n): outer dimensions survive, the inner one is summed away.

The @ Operator

Python gives matrix multiply its own clean symbol. The @ operator multiplies two tensors the matrix way, no loops in sight.

c = a @ b

torch.matmul Does the Same

torch.matmul is the spelled-out twin of @. Same result, handy when you prefer a named function call in your code.

c = torch.matmul(a, b)

Mind the Shapes

A (2, 3) times a (3, 4) gives a (2, 4). Read the shapes left to right and the inner 3 cancels, leaving the outer pair.

a = torch.randn(2, 3)
b = torch.randn(3, 4)
c = a @ b  # shape (2, 4)

Star Is Not At

Do not confuse them: a * b is elementwise and needs matching shapes, while a @ b is matrix multiply and needs matching inner dimensions.

Matrix Times Vector

Multiply a matrix by a 1D vector and you get a vector. Each output number is the dot product of a matrix row with that vector.

y = W @ x  # W is (n, m), x is (m,), y is (n,)

Batched matmul

matmul handles batches: feed shapes (B, m, k) and (B, k, n) and it multiplies each of the B matrix pairs at once, returning (B, m, n).

out = torch.matmul(batch_a, batch_b)

Shape Errors Are Loud

Mismatch the inner dimensions and PyTorch throws a clear RuntimeError. Reading those shape messages quickly becomes your fastest debugging tool.

The Engine of Every Layer

This one operation is everywhere. A linear layer is just inputs times a weight matrix plus a bias, and matmul does that heavy lifting.

out = x @ W.T + bias

Quick Check

Time to check your shape arithmetic.

Recap: Rows Meet Columns

Matrix multiply with @ or torch.matmul pairs rows with columns into dot products; inner dimensions must match, outer ones survive. It powers every layer. 🔗

Frequently asked questions

Is the “Matrix Multiply with matmul and @” lesson free?

Yes — the full text of “Matrix Multiply with matmul and @” is free to read here on the web, and the Deep Learning 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 Deep Learning Academy course, upgrade to CoddyKit PRO.

What will I learn in “Matrix Multiply with matmul and @”?

The dot products behind every layer. You practise Deep Learning 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 Deep Learning Academy?

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

How long does the “Matrix Multiply with matmul and @” 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 Deep Learning Academy lesson?

Yes. Every Deep Learning 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. Why Loops Are Slow for Math
  2. Elementwise Ops & Reductions
  3. Matrix Multiply with matmul and @
  4. Dot Products Power Every Layer
← Back to Deep Learning Academy