Say I've got
Y = np.array([2, 0, 1, 1])
From this I want to obtain a matrix X with shape (len(Y), 3)
. In this particular case, the first row of X should have a one on the second index and zero otherwhise. The second row of X should have a one on the 0 index and zero otherwise. To be explicit:
X = np.array([[0, 0, 1], [1, 0, 0], [0, 1, 0], [0, 1, 0]])
How do I produce this matrix?
I started with
X = np.zeros((Y.shape[0], 3))
but then couldn't figure out how to populate/fill in the ones from the list of indices
As always, thanks for your time!
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…