The team needs a reliable implementation for traffic-distribution monitoring in a production-oriented ML workflow. A small implementation error can change the model input or metric enough to make a downstream result misleading.
Compute Shannon entropy for a probability vector representing user-click outcomes.
Use base-2 logarithms so the answer is in bits. The input must be a non-empty 1-D vector of non-negative values that sums to 1, otherwise ValueError is raised; zero probabilities contribute nothing.
Implement solve(p).
Returns. Return the entropy as a non-negative Python float.
Example 1
Input:
solve([0.5, 0.5])
Output:
1.0
Example 2
Input:
solve([0.9, 0.1])
Output:
0.468996
Example 3
Input:
solve([1.0, 0.0])
Output:
0.0
Example 4
Input:
solve([0.5, 0.6])
Output: Raises ValueError.
No results yet
Run your code to check it against the examples, or submit to run every test.