Join Our 5-Week ML/AI Engineer Interview Bootcamp ๐Ÿš€ led by ML Tech Leads at FAANGs

Back to Questions

266. Perceptron forward pass

easy
GeneralGeneral
senior

Implement the forward pass of a binary perceptron, which maps an input feature vector to a predicted class using a weighted sum and a step activation. This checks your understanding of basic neural network computation in deep learning fundamentals.

Requirements

Implement the function

python

Rules:

  • Compute the logit using the formula z=โˆ‘i=1dwixi+bz = \sum_{i=1}^{d} w_i x_i + b.
  • Return 1 if z >= 0, otherwise return 0.
  • Use only NumPy and/or Python built-in libraries (no ML frameworks).
  • Do not use any prebuilt perceptron or classifier utilities.

Example

python

Output:

python
Input Signature
ArgumentType
bfloat
wnp.ndarray
xnp.ndarray
Output Signature
Return NameType
valueint

Constraints

  • x and w must have equal length

  • Use only Python/NumPy; no ML frameworks

  • Return int label 0 or 1

Hint 1

Start by computing the dot product between w and x: multiply each wi * xi and sum them.

Hint 2

After the dot product, add the bias: z = (sum of wi*xi) + b.

Hint 3

Apply the step activation exactly as specified: return 1 if z >= 0, else 0 (note the >=).

Roles
ML Engineer
AI Engineer
Companies
GeneralGeneral
Levels
senior
entry
Tags
perceptron
dot-product
threshold-activation
binary-classification
37 people are solving this problem
Python LogoPython Editor
Ln 1, Col 1

Input Arguments

Edit values below to test with custom inputs

You need tolog in/sign upto run or submit