From e63bbffaac4e756b89a4f81882d757de44e0e2a7 Mon Sep 17 00:00:00 2001 From: Brandon Rozek Date: Sun, 11 Oct 2020 22:04:08 -0400 Subject: [PATCH] New Post --- content/blog/reverseonehotencode.md | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 content/blog/reverseonehotencode.md diff --git a/content/blog/reverseonehotencode.md b/content/blog/reverseonehotencode.md new file mode 100644 index 0000000..8161121 --- /dev/null +++ b/content/blog/reverseonehotencode.md @@ -0,0 +1,22 @@ +--- +title: "Reverse One-Hot Encode" +date: 2020-10-11T21:58:47-04:00 +draft: false +tags: [] +--- + +Let's say that you have a dataset that is one hot encoded like the following observation: + +```python +import numpy as np +obs = np.array([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0]) +``` + +The easiest way to reverse one-hot encode the structure, is to take the `argmax` of the observation. + +```python +reverse_encoding = np.argmax(obs) +# 13 +``` +