A small code snippet for non-linear mapping in Python/Javascript