Ask a Question
Ask Question Login
Corporate Training
  1. Community
  2. Devops
  3. Question
Devops

Convert array of indices to 1-hot encoded numpy array

Asked by Clare Matthews Jul 1, 2021 2.7K views 1 answer
Share

About this question

I want to encode a 1-D numpy array:

x = array([1,0,3]) 

As a 2-D 1-hot array

y = array([[0,1,0,0], [1,0,0,0], [0,0,0,1]])

Suggest me some faster technique other than looping. 

Your answer

1 Answer

More Devops discussions

Learn & Explore

Free tutorials and interview questions from industry experts — learn the skill, then get ready to prove it.

Latest DevOps Blogs

Guides, tips and career advice on DevOps from JanBask experts.