Matrix Multiplication Calculator
Enter values into matrices A and B, then click Multiply. Supports dimensions up to 6×6. B's row count is automatically locked to A's column count.
🔒100% Client-Side. Everything runs in your browser — no data is sent to any server.
Matrix A:×|Matrix B:×
Matrix A (2×3)
×
Matrix B (3×2)
Matrix multiplication in NumPy
import numpy as np
A = np.array([[1, 2, 3],
[4, 5, 6]]) # shape (2, 3)
B = np.array([[7, 8],
[9, 10],
[11, 12]]) # shape (3, 2)
# Matrix multiplication (requires A.cols == B.rows)
C = A @ B # or np.matmul(A, B)
print(C)
# [[ 58 64]
# [139 154]]
print(f"Shape: {'{A.shape}'} @ {'{B.shape}'} = {'{C.shape}'}")
Why matrix multiplication matters in ML
Neural network forward passes are sequences of matrix multiplications. A linear (fully connected) layer computes output = X @ W.T + b, where X is the input batch, W is the weight matrix, and b is the bias vector. Understanding shapes — (batch_size, in_features) × (in_features, out_features) = (batch_size, out_features) — is essential for debugging dimension errors in PyTorch or TensorFlow. Getting matrix shapes wrong is one of the most common sources of bugs when building custom layers or loss functions.
import torch
# Simulate a linear layer
batch_size, in_features, out_features = 32, 128, 64
X = torch.randn(batch_size, in_features)
W = torch.randn(out_features, in_features)
b = torch.randn(out_features)
output = X @ W.T + b
print(output.shape) # torch.Size([32, 64])