Advertisement
Guest User

one hot encoding

a guest
May 17th, 2018
155
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.22 KB | None | 0 0
  1. def one_hot_encode(y):
  2. encoded = np.zeros((y.shape[0], 3))
  3.  
  4. for i, l in enumerate(y):
  5. encoded[i, l] = 1.
  6.  
  7. return encoded
  8.  
  9. encoded = one_hot_encode(labels)
  10. print(encoded[[0, 51, 101]])
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement