Example #1
0
def one_hot_encode(data, channels=256):
    """
    the return of this function is a numpy array shaped as [C(channels), L(timestep)]
    """
    one_hot = np.zeros((channels, data.size), dtype=float)
    one_hot[data.ravel(), np.arange(data.size)] = 1

    return one_hot
Example #2
0
def one_hot_encode(data, channels=256):
    #print(data, data.size, data.shape)
    one_hot = np.zeros((data.size, channels), dtype=float)
    one_hot[np.arange(data.size), data.ravel()] = 1

    return one_hot
Example #3
0
def onehot(data, n):
    buf = np.zeros(data.shape + (n, ))
    nmsk = np.arange(data.size)*n + data.ravel()
    buf.ravel()[nmsk-1] = 1
    return buf