Skip to content
Calcrivo

Matrix Multiplication Calculator

Multiply two matrices and compute the resulting matrix and operation count.

Inputs

Result Elements

6

Total Scalar Operations

42

Multiplications

24

Step by step

  1. Result matrix shape

    (3×4) × (4×2)

    = 3×2

  2. Scalar multiplications: m × k × n

    3 × 4 × 2

    = 24

  3. Scalar additions: m × (k−1) × n

    3 × 3 × 2

    = 18

How it works

Matrix multiplication (matmul) is the core operation in neural networks — every linear layer, attention mechanism, and convolution can be expressed as matmuls. For A(m×k) × B(k×n), the result is an m×n matrix requiring m×k×n multiplications and m×(k-1)×n additions.

Formula

Matrix Multiply

C[i,j] = sum(A[i,k] * B[k,j]) for k=1..K

m, k, n
Dimensions of input and output matrices

Frequently Asked Questions

Why is matrix multiplication so important in deep learning?

Every fully connected layer computes Y = XW + b, which is a matrix multiplication. Transformers, CNNs (via im2col), and RNNs all reduce to batched matmuls, making it the single most performance-critical operation in ML.

How does this relate to FLOPs calculations?

The FLOPs for a matmul are typically counted as 2×m×k×n (counting multiply and add as separate operations), which is the standard used by hardware vendors and ML papers.

You might also need