Neural Network Basics
Medium
Dense Layer Forward Pass
Medium
~18 min
code completion
Dense Layer Forward Pass
A single dense (fully connected) layer computes:
where:
This combines a linear transformation (the matrix multiply + bias) with a nonlinearity (ReLU) — the building block of deep networks.
Your task:
Implement dense_forward(X, W, b) that returns relu(X @ W + b).
Example Tests
Negative pre-activation clipped to 0
Input: {"W":[[1,-1],[2,-2]],"X":[[1,2]],"b":[0,0]}
Expected: [[5,0]]
Identity-like weights with bias
Input: {"W":[[1],[1]],"X":[[1,0],[0,1]],"b":[0]}
Expected: [[1],[1]]
Output shape is (m, n_out)
Input: {"W":[[1,0],[0,1],[1,1]],"X":[[1,2,3],[4,5,6]],"b":[0,0]}
Expected: [2,2]