#165Dense layer — sigmoid forward passEasyNeural NetworksActivation Functions
Dense layer — sigmoid forward pass
Background
One dense layer's forward pass is a linear step followed by an activation. With the canonical sigmoid:
Here W has shape (n_out, n_in), so W @ x produces one score per output neuron, the bias shifts each, and the sigmoid squashes each into .
Problem statement
Implement layer_forward(x, W, b) returning .
Input
x— array-like input vector of lengthn_in.W— array-like weight matrix of shape(n_out, n_in).b— array-like bias vector of lengthn_out.
Output
Returns an np.ndarray of shape (n_out,): the layer's activation.
Examples
Example 1 — zero score is 0.5
Input: x = [0, 0], W = [[1, 0], [0, 1]], b = [0, 0]
Output: [0.5 0.5]
Explanation: , and per neuron.
Example 2
Input: x = [1, 1], W = [[1, 2]], b = [-1]
Output: [0.88079708]
Explanation: , and .
Constraints
- Compute
W @ x + b, then apply the sigmoid elementwise. - Return an
np.ndarrayof shape(n_out,).
Notes
- This single layer is the building block of the whole stack — feeding its output into another
layer_forwardis exactly what "depth" means.
Python
Loading...
▶ Run executes the 3 visible sample tests below in your browser. Submit runs the full suite — including hidden tests — on the server for an official verdict.
- •Example: zero score gives one half per neuron
- •Reference: single output neuron with z equal to two
- •Sample: three-neuron layer output