Dataford
Interview QuestionsInterview GuidesExperiencesCoaching
New
Pricing
Get started
Dataford
Popular roles
Software EngineerData AnalystData ScientistData EngineerBusiness AnalystAI EngineerMachine Learning EngineerProduct Manager
Browse
Browse All RolesEvery role hub, from analyst to MLBrowse All CompaniesCompany-specific interview loopsAll Interview GuidesThe full guide library
Top questions by role
Software EngineerData AnalystData ScientistData EngineerBusiness AnalystAI EngineerMachine Learning EngineerProduct Manager
Top questions by skill
SQLPythonStatisticsMachine LearningA/B TestingSystem DesignGenerative AIProduct SenseMetricsBehavioral
Browse all questions →Try a mock interview
ExperiencesCoaching
New
Practice
Mock InterviewsTimed interview simulations with feedbackSuccess PathYour 6-week structured planModulesCurated lessons by topicWebinarsTalks from ex-Big Tech data leadsPlaygroundA free-form scratch editor
Learn
BlogInterview strategy and career adviceTech Job Market ReportHiring trends across data and AI rolesFor UniversitiesDataford for career centersAbout DatafordWho we are and how we build
Pricing
Get started
Neural Network Forward Pass in NumPy
00:00
5 left

Neural Network Forward Pass in NumPy

HardPython

Problem

Implement a simple neural network forward pass in NumPy.

Use fully connected layers, apply ReLU after every hidden layer, and apply numerically stable softmax to the final logits. The function receives X as a batch matrix, weights as matrices shaped (input_dim, output_dim), and biases as vectors. Return the output probabilities as a nested Python list with one row per input example.

Example: X = [[0, 0]], one zero-weight layer produces [[0.5, 0.5]]. A network with negative hidden activations must apply ReLU before the next layer.

Constraints

  • 1 <= number of input examples <= 1000
  • 1 <= number of layers <= 10
  • Each weight matrix has shape (previous_layer_width, current_layer_width)
  • Each bias vector has length equal to its layer's output width
  • The input and every layer contain at least one feature
  • All values are finite real numbers

Function Signature

def neural_network_forward(X, weights, biases):
Interviewer

Your question is Neural Network Forward Pass in NumPy. Start with the requirements in the Question tab.

Run and submit as often as you like. When you're ready, talk me through your approach or go straight to the code.

You need to log in / sign up to run or submit.
CodePython 3
Sign up free to run your codeLog inLn 2
Run your code to see test output here.