Compute the Shannon entropy, in bits, of a discrete probability vector.
Implement solve(p).
Returns. Return a float. Entries equal to zero contribute nothing. The input must be a non-empty 1-D vector of non-negative values that sums to 1; otherwise ValueError is raised.
Example 1
Input:
solve([0.5, 0.5])
Output:
1.0
Example 2
Input:
solve([0.25, 0.25, 0.25, 0.25])
Output:
2.0
No results yet
Run your code to check it against the examples, or submit to run every test.