简体   繁体   中英

Step function with linear inteval in numpy

I want to implement for a step function in numpy with the definition:

在此处输入图片说明

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

在此处输入图片说明

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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