Kolibril
Kolibril

Reputation: 1423

Step function with linear inteval in numpy

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

enter image description here

Upvotes: 0

Views: 789

Answers (1)

ImportanceOfBeingErnest
ImportanceOfBeingErnest

Reputation: 339340

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

enter image description here

Upvotes: 1

Related Questions