Last active
January 22, 2019 00:40
-
-
Save sccu/4d281e8b09a508902d48eba9bbb6f657 to your computer and use it in GitHub Desktop.
Unsaturated scale function in python
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from matplotlib import pyplot | |
import numpy as np | |
def scale(x, k=1.0, func="log"): | |
k = max(1e-9, abs(k)) | |
if func == "log": | |
return np.sign(x) * np.log(k*np.abs(x)+1) / k | |
elif func == "sqrt": | |
return np.sign(x) * (np.sqrt(k*np.abs(x)+1) * 2 - 2) / k | |
else: | |
raise ValueError(f"Invalid func name: {func}") | |
x = [i for i in range(-100, 100)] | |
pyplot.plot(x, scale(x)) | |
pyplot.grid(b=True) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment