Skip to content
DeepForgeby svx
All problems
EasyDeep Learningdl-010

Dense Layer Forward

Problem

Compute one dense (fully connected) layer without an activation: y = W @ x + b.

The signature is dense_forward(x, W, b). W has shape (output_dim, input_dim), x has length input_dim and b has length output_dim.

Hint

One dot product per output row of W, then add the bias.

Test cases

case 1
in: [[1,2],[[1,0],[0,1]],[0.5,-0.5]]
expected: [1.5,1.5]
case 2
in: [[2],[[3]],[1]]
expected: [7]
case 3
in: [[1,-1],[[2,3]],[0]]
expected: [-1]
case 4
in: [[0.5,0.5],[[1,1],[2,2]],[0,0]]
expected: [1,2]
case 5
in: [[1,2,3],[[1,-1,0.5]],[2]]
expected: [2.5]
Starter codePython
def dense_forward(x, W, b):
    # Your code here
    pass

5 test cases · run your code against them in the editor