简体   繁体   English

numpy中具有线性整数的阶跃函数

[英]Step function with linear inteval in numpy

I want to implement for a step function in numpy with the definition: 我想用以下定义在numpy中实现步进功能:

在此处输入图片说明

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()

在此处输入图片说明

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM