import array


def ordinate(values,maxrange,levels):
    """Ordinate values given a maximum data range and number of levels
    
    Parameters:
    1. values: an array of continuous values to ordinate
    2. maxrange: the maximum data range. Values larger than this will be saturated.
    3. levels: the number of levels at which values are ordinated
    
    """
    
    quantizer=lambda dist,maxrange,levels: int(1.0*max(1,dist-1)*levels/maxrange)+1
    if type(values)==list or type(values)==tuple or type(values)==array:
        ordinated=[]
        for v in values:
            if v==0:
                ordinated.append(v)
            else:
                ordinated.append(quantizer(v,maxrange,levels))
        return ordinated
    else:
        if values==0:
            return values
        else:
            return quantizer(values,maxrange,levels)