One-Hot Encoder
Start Timer
0:00:00
Given a list, write a function encode
which one-hot encodes the items in the list. When one-hot encoding, the most significant bit (index zero) should be represented by the first unique element in the list.
Example 1:
Input:
elements = [1, 3, 4, 3, 2, 1]
Output:
def encode(elements) -> [[1, 0, 0, 0], [0, 1, 0, 0],
[0, 0, 1, 0], [0, 1, 0, 0], [0, 0, 0, 1], [1, 0, 0, 0]]
Example 2:
Input:
elements = ['hi', 'hello', 'amazing', 'amazing']
Output:
def encode(elements) -> [[1, 0, 0], [0, 1, 0], [0, 0, 1], [0, 0, 1]]
Recommended questions for you
Personalized based on your user activity, skill level, and preferences.
.
.
.
.
.
.
.
.
.
Comments