Step function with linear inteval in numpy

别等时光非礼了梦想. 提交于 2021-02-11 17:41:41

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!