【发布时间】:2016-12-15 04:00:03
【问题描述】:
import numpy as np
from keras.utils import np_utils
nsample = 100
sample_space = ["HOME","DRAW","AWAY"]
array = np.random.choice(sample_space, nsample, )
uniques, coded_id = np.unique(array, return_inverse=True)
coded_array = np_utils.to_categorical(coded_id)
例子
输入
['AWAY', 'HOME', 'DRAW', 'AWAY', ...]
输出编码数组
[[ 0. 1. 0.]
[ 0. 0. 1.]
[ 0. 0. 1.]
...,
[ 0. 0. 1.]
[ 0. 0. 1.]
[ 1. 0. 0.]]
如何逆向处理并从 coded_array 中获取原始数据?
【问题讨论】:
-
您想要获得
ids还是arr?如果arr,我想我们也需要uniques。 -
我在找arr
-
那么,我们是否也将
uniques作为decode()的输入? -
我可以这样做,在编码处返回两个元素