10000 Feature Request: Linear step function (similar to numpy.heaviside) · Issue #14314 · numpy/numpy · GitHub
[go: up one dir, main page]

Skip to content
Feature Request: Linear step function (similar to numpy.heaviside) #14314
Closed
@kolibril13

Description

@kolibril13

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0