PIXELBANKv9.1.0
Menu

Implement a single perceptron forward pass.

Given an input vector xx, weight vector ww, and bias bb, compute:

z=w⋅x+bz = w \cdot x + b output={1if z≥00otherwise\text{output} = \begin{cases} 1 & \text{if } z \geq 0 \\ 0 & \text{otherwise} \end{cases}

Process multiple input samples and return a list of outputs.

Example:

Input:
X = [[1, 1], [0, 1], [1, 0], [0, 0]]
w = [1, 1]
b = -1.5
Output:
[1, 0, 0, 0]
Reasoning:
  • We calculate zz for each input sample by taking the dot product of the input vector xx and weight vector ww, then adding the bias bb. For the first sample, this gives z=(1â‹…1)+(1â‹…1)−1.5=0.5z = (1 \cdot 1) + (1 \cdot 1) - 1.5 = 0.5.
  • We apply the activation function to each zz value: for the first sample, since z=0.5≥0z = 0.5 \geq 0, the output is 11. For the other samples:
    • x=[0,1]x = [0, 1]: z=(0â‹…1)+(1â‹…1)−1.5=−0.5z = (0 \cdot 1) + (1 \cdot 1) - 1.5 = -0.5, output is 00
    • x=[1,0]x = [1, 0]: z=(1â‹…1)+(0â‹…1)−1.5=−0.5z = (1 \cdot 1) + (0 \cdot 1) - 1.5 = -0.5, output is 00
    • x=[0,0]x = [0, 0]: z=(0â‹…1)+(0â‹…1)−1.5=−1.5z = (0 \cdot 1) + (0 \cdot 1) - 1.5 = -1.5, output is 00
  • The final output is a list of these results: [1,0,0,0][1, 0, 0, 0]

Constraints:

  • X: 2D list of input vectors
  • w: list of weights
  • b: scalar bias
  • Return list of 0 or 1 outputs
solution.py

Test Results

0/0
Run code to see test results.
Single Perceptron - Easy | PixelBank