def binary_one_hot(x):
try:
if type(x).__module__ == np.__name__:
dim0 = x.shape[0]
elif isinstance(x, list):
dim0 = len(x)
else:
raise TypeError
except TypeError:
print("Expecting input type to be one of {list, numpy.ndarray}. Received %s" % type(x))
dim1 = 2
output = np.zeros((dim0, dim1))
for i in range(dim0):
output[i, x[i]] = 1
return output
评论列表
文章目录