Closed
Description
Often I use this function:
which is defined as:
So very similar to the numpy heaviside function, but with an linear interval between 0 and 1.
Therefore I wrote the function "linear_step_func".
Is there an interest of making it a numpy function?
import numpy as np
import matplotlib.pyplot as plt
x= np.linspace(0., 10., 100)
def linear_step_func(x,x0,x1):
y= np.piecewise(x, [
x < x0,
(x >= x0) & (x <= x1),
x > x1],
[0.,
lambda x: x/(x1-x0)+x0/(x0-x1),
1.]
)
return y
plt.plot(x, linear_step_func(x,2, 5))
plt.show()
Metadata
Metadata
Assignees
Labels
No labels