Mockbit/#92
MLmediumActivation functions~10m

Stable Softmax Activation Function

Problem

Implement the softmax activation function with numerical stability using only NumPy. Apply softmax to each row independently, subtracting the maximum value from each row before computing exponentials to prevent overflow.

Examples

Example 1

Input: [[1, 2, 3], [4, 5, 6]]
Output: [[0.09003, 0.24473, 0.66524], [0.09003, 0.24473, 0.66524]]

Softmax converts logits to probabilities, each row sums to 1.

Constraints
  • NumPy only (import numpy as np)
  • Function must be named solution
Reference solution

Reference solution available after you attempt the question.

Ready to solve it?

Start a session on Mockbit #92. You'll get graded with specific critique when you submit.

Related ML questions
← Back homemockbit.io/q/92
PrivacyTerms© 2026 Mockbit