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
J

James Atwood

Guest
Given a 1D array of indices:

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

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

Code:
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])
</code></pre>
<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]])
</code></pre>
 

Latest posts

Online statistics

Members online
1
Guests online
6
Total visitors
7
Top