Softmax

MediumMachine LearningMathArray

Description

Given an array of numbers logits, return the softmax probabilities (exp of each value divided by the sum of all exps), each rounded to 4 decimal places.

Examples

Input:logits = [1,2,3]
Output:[0.09,0.2447,0.6652]
Explanation:

Exponentiating and normalizing the values into probabilities gives [0.09,0.2447,0.6652].

Input:logits = [0,0,0]
Output:[0.3333,0.3333,0.3333]
Explanation:

Exponentiating and normalizing the values into probabilities gives [0.3333,0.3333,0.3333].

Input:logits = [2,1]
Output:[0.7311,0.2689]
Explanation:

Exponentiating and normalizing the values into probabilities gives [0.7311,0.2689].

Constraints

  • 1 ≤ logits.length ≤ 10³

Ready to solve this problem?

Practice solo and sharpen your skills for technical interviews.