Dense Layer Forward Pass

~18 mincode completion

Implement dense_forward(X, W, b) that returns .

Examples

Negative pre-activation clipped to 0

Input
dense_forward([[1, 2]], [[1, -1], [2, -2]], [0, 0])
Output
[[5, 0]]

Identity-like weights with bias

Input
dense_forward([[1, 0], [0, 1]], [[1], [1]], [0])
Output
[[1], [1]]

Hints

Hint 1

compares elementwise against a scalar or another array.

Hint 2

Do not forget to relu. That step is easy to skip.

Requirements

  • X: Input matrix of shape (m, n_in)

  • : Weight matrix of shape (n_in, n_out)

  • b: Bias vector of shape (n_out,)

  • Return Output matrix of shape (m, n_out) after ReLU.

Constraints

  • Allowed library: NumPy only

  • Time limit: 200 ms, Memory: 64 MB

Where this shows up

~18 min

8 employers weight this skill

4 frontier labs, 2 big tech firms, 1 autonomy company, 1 enterprise vendor. Top match scores 92.

Python
import numpy as np

def dense_forward(X: np.ndarray, W: np.ndarray, b: np.ndarray) -> np.ndarray:
    """
    Compute the forward pass of a dense (ReLU) layer.

    Args:
        X: Input matrix of shape (m, n_in)
        W: Weight matrix of shape (n_in, n_out)
        b: Bias vector of shape (n_out,)

    Returns:
        Output matrix of shape (m, n_out) after ReLU.
    """
    # YOUR CODE HERE
    pass
Loading docs…

The AI Mentor needs an account

It reads your code and the failing tests and nudges you toward the fix without handing you the answer. Free accounts get it on every problem you're working on today.