#163Neuron — the linear score z = wᵀx + bEasy

Neuron — the linear score z = wᵀx + b

Background

Every neuron starts the same way: an affine map of the inputs.

z=w⊤x+bz = \mathbf{w}^\top \mathbf{x} + b

This single number zz is the neuron's pre-activation score. Linear regression, logistic regression, and the perceptron all compute this same zz — they differ only in what they do after it. Getting zz right is the foundation of the whole course.

Problem statement

Implement neuron_score(x, w, b) returning the scalar w⊤x+b\mathbf{w}^\top\mathbf{x} + b for one input.

Input

  • x — array-like feature vector of length nn.
  • w — array-like weight vector of length nn.
  • b — float, the bias.

Output

Returns a Python float: the linear score zz.

Examples

Example 1

Input:  x = [2, 3], w = [2, 3], b = -5
Output: 8.0

Explanation: 2⋅2+3⋅3−5=4+9−5=82\cdot2 + 3\cdot3 - 5 = 4 + 9 - 5 = 8.

Example 2 — bias shifts the score

Input:  x = [0, 0], w = [1, 1], b = 0.7
Output: 0.7

Explanation: with zero inputs only the bias survives, which is exactly why bb lets the boundary avoid the origin.

Constraints

  • Compute the dot product w⊤x\mathbf{w}^\top\mathbf{x} and add b.
  • Return a plain float.

Notes

  • The bias bb shifts zz up or down independently of the inputs — that is what lets a neuron's decision boundary sit anywhere, not just through the origin.
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 score
  • •reference bias only
  • •sample negative score