Premium problem136. Gradient of Softmax Cross-Entropy

Hard Locked

Given logits Z (n, k) and integer labels y (n,), return the (n, k) array dL/dZ where L is the mean softmax cross-entropy loss.

Input

Z =
[[1. 2. 3.]
 [3. 1. 0.]]
y = [2 0]

Output

[[ 0.04501529  0.12236424 -0.16737952]
 [-0.07810263  0.0570976   0.02100503]]

Premium problem

This one's part of Premium. Unlock the full NumPy track plus every other premium problem on the site.

Implement solve(...)