codes is a 1-D integer array with values in [0, k). Return the (n, k) integer matrix whose row i has a 1 in column codes[i] and 0 elsewhere.
codes
[0, k)
(n, k)
i
codes[i]
Input
codes = [0 2 1 2] k = 3
Output
[[1 0 0] [0 0 1] [0 1 0] [0 0 1]]
This one's part of Premium. Unlock the full NumPy track plus every other premium problem on the site.
solve(...)