0

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

enter image description here

1 Answer 1

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

enter image description here

Sign up to request clarification or add additional context in comments.

1 Comment

Nice, np.piecewise is what I was looking for

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.