Skip to content

Feature Request: Linear step function (similar to numpy.heaviside) #14314

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
kolibril13 opened this issue Aug 21, 2019 · 7 comments
Closed

Feature Request: Linear step function (similar to numpy.heaviside) #14314

kolibril13 opened this issue Aug 21, 2019 · 7 comments

Comments

@kolibril13
Copy link

Often I use this function:
image
which is defined as:
func
So very similar to the numpy heaviside function, but with an linear interval between 0 and 1.
Therefore I wrote the function "linear_step_func".
Is there an interest of making it a numpy function?

import numpy as np
import matplotlib.pyplot as plt

x= np.linspace(0., 10., 100)
def linear_step_func(x,x0,x1):
    y= np.piecewise(x, [
        x < x0, 
       (x >= x0) & (x <= x1), 
        x > x1],
            [0.,
            lambda x: x/(x1-x0)+x0/(x0-x1), 
             1.]
       )
    return y
plt.plot(x, linear_step_func(x,2, 5))
plt.show()
@rgommers
Copy link
Member

Thanks for asking @kolibril13. I think that doesn't meet our bar for inclusion in NumPy itself (which is high these days). It's fairly easy to do yourself if you need this, as your code shows. There's many such utility functions we could include, but it would fill up the numpy namespace with things most users may never need.

@kolibril13
Copy link
Author

ok, thanks!

@eric-wieser
Copy link
Member

I'm starting to wonder whether heaviside met the bar for inclusion, not that that matters now.

@rgommers
Copy link
Member

It wouldn't today for sure I think. The bar was a lot lower 10-15 years ago.

@eric-wieser
Copy link
Member

Well, that was only two years ago (gh-8795)

@rgommers
Copy link
Member

Well, that was only two years ago (gh-8795)

hmm I totally missed that. I think that was a mistake.

@Mastercol01
Copy link

I'm starting to wonder whether heaviside met the bar for inclusion, not that that matters now.

Well, I cannot talk for any other developers, but, as STEM student, I can tell you it has proven useful quite sometimes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants