pythonnumpy
Ben Gorman

Ben Gorman

Life's a garden. Dig it.

Given a 1d array of integers, one-hot-encode it into a 2d array. In other words, convert this 1-d array called yoyoyo,

import numpy as np
yoyoyo = np.array([3, 1, 0, 1])

into a 2-d array like this.

# [[0. 0. 0. 1.]
#  [0. 1. 0. 0.]
#  [1. 0. 0. 0.]
#  [0. 1. 0. 0.]]

Solution 1

This content is gated

Subscribe to one of the products below to gain access

Solution 2

This content is gated

Subscribe to one of the products below to gain access