Mnożenie macierzy za pomocą matmul i @
Poznać iloczyny skalarnе leżące u podstaw każdej warstwy
Mnożenie macierzy za pomocą matmul i @ to bezpłatna lekcja Deep Learning Academy na CoddyKit. To lekcja 3 z 4. Możesz przeczytać całą lekcję poniżej za darmo — a potem ćwiczyć ją interaktywnie w przeglądarce z wbudowanym edytorem kodu i tutorem AI dostępnym 24/7. To część ścieżki edukacyjnej Deep Learning Academy, a Twój postęp synchronizuje się między webem a aplikacją CoddyKit. Kurs Deep Learning Academy zawiera 4 lekcji w sumie.
Części tej lekcji nie zostały jeszcze przetłumaczone i są wyświetlane po angielsku.
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 @ btorch.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 + biasQuick 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. 🔗
Często zadawane pytania
Czy lekcja „Mnożenie macierzy za pomocą matmul i @” jest bezpłatna?
Tak — pełny tekst „Mnożenie macierzy za pomocą matmul i @” jest dostępny za darmo tutaj w sieci. Aby ćwiczyć ją interaktywnie (wbudowany edytor kodu i tutor AI dostępny 24/7) i odblokować resztę kursu Deep Learning Academy, przejdź na CoddyKit PRO. Kurs Deep Learning Academy zawiera 4 lekcji w sumie.
Co nauczysz się w „Mnożenie macierzy za pomocą matmul i @”?
Poznać iloczyny skalarnе leżące u podstaw każdej warstwy Ćwiczysz Deep Learning Academy z praktycznym kodem, który uruchamiasz bezpośrednio w przeglądarce, a tutor AI dostępny 24/7 odpowiada na Twoje pytania podczas pracy nad lekcją.
Czy potrzebuję doświadczenia, aby zacząć Deep Learning Academy?
Nie wymagamy żadnego doświadczenia. Deep Learning Academy w CoddyKit jest strukturyzowany dla początkujących i zaawansowanych użytkowników, więc możesz zacząć tutaj lub od początku i uczyć się w swoim tempie. To lekcja 3 z 4.
Ile czasu zajmuje lekcja „Mnożenie macierzy za pomocą matmul i @”?
Większość lekcji CoddyKit trwa około 5–10 minut. Każda lekcja to mały, interaktywny krok, dzięki czemu robisz systematyczne postępy i zawsze wracasz dokładnie do tego samego miejsca — na webie i w aplikacji.
Czy mogę pisać i uruchamiać kod w tej lekcji Deep Learning Academy?
Tak. Każda lekcja Deep Learning Academy zawiera wbudowany edytor kodu, więc piszesz i uruchamiasz prawdziwy kod bezpośrednio w przeglądarce i od razu otrzymujesz sprzężenie zwrotne od AI — bez konfiguracji na komputerze.
Wszystkie lekcje w tym kursie
- Dlaczego pętle są wolne w obliczeniach matematycznych
- Operacje elementowe i redukcje
- Mnożenie macierzy za pomocą matmul i @
- Iloczyny skalarne napędzają każdą warstwę