def discretize(value, n_dim, min_val, max_val):
    """
    discretize a value into a vector of n_dim dimension 1-hot representation
    with the value below min_val being [1, 0, 0, ..., 0]
    and the value above max_val being [0, 0, ..., 0, 1]
    Args:
        value: the value that needs to be discretized into 1-hot format
        n_dim: number of dimensions
        min_val: minimal value in the result
        man_val: maximum value in the result
    Returns:
        the discretized vector
    """
    assert n_dim > 0
    if n_dim == 1:
        return [1]
    delta = (max_val - min_val) / float(n_dim - 1)
    active_pos = int((value - min_val) / delta + 0.5)
    active_pos = min(n_dim - 1, active_pos)
    active_pos = max(0, active_pos)
    ret_array = [(0) for i in range(n_dim)]
    ret_array[active_pos] = 1.0
    return ret_array
