OiO.lk Community platform!

Oio.lk is an excellent forum for developers, providing a wide range of resources, discussions, and support for those in the developer community. Join oio.lk today to connect with like-minded professionals, share insights, and stay updated on the latest trends and technologies in the development field.
  You need to log in or register to access the solved answers to this problem.
  • You have reached the maximum number of guest views allowed
  • Please register below to remove this limitation

Convert array of indices to one-hot encoded array in NumPy

  • Thread starter Thread starter James Atwood
  • Start date Start date

James Atwood

Given a 1D array of indices:

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

I want to one-hot encode this as a 2D array:

b = array([[0,1,0,0], [1,0,0,0], [0,0,0,1]])
<p>Given a 1D array of indices:</p>
<pre><code>a = array([1, 0, 3])
<p>I want to one-hot encode this as a 2D array:</p>
<pre><code>b = array([[0,1,0,0], [1,0,0,0], [0,0,0,1]])

Latest posts

Online statistics

Members online
Guests online
Total visitors