问题
I want to implement for a step function in numpy with the definition:
回答1:
Since the other answer does not implement the function in the question, here is a correct soluton:
import numpy as np
import matplotlib.pyplot as plt
x= np.linspace(0., 50., 1001)
f = lambda x0, x1: np.piecewise(x, [x < x0, (x >= x0) & (x <= x1), x > x1],
[0., lambda x: x/x0, 1.])
plt.plot(x, f(10, 30))
plt.show()
来源:https://stackoverflow.com/questions/57516274/step-function-with-linear-inteval-in-numpy