[SciPy-user] I can't find unit step function.

Hui Chang Moon topengineer@gmail....
Tue Mar 20 02:54:35 CDT 2007


Thank you for your kindness~!
Have a nice day~!!


2007/3/20, Anne Archibald <peridot.faceted@gmail.com>:
>
> On 20/03/07, David Warde-Farley <david.warde.farley@utoronto.ca> wrote:
> > On Tue, 2007-03-20 at 16:20 +0900, Hui Chang Moon wrote:
> > > Hello, users,
> > >
> > > Scipy has many convenient functions, so I can't find the function that
> > > I am willing to use.
> > > So, anybody help me find the unit step function.
> >
> > That might be just a little too basic for a built-in. But you can easily
> > define it.
> >
> > def step(x):
> >         if x == 0: return 0.5
> >         return x > 0 and 1 or 0
>
> You might prefer that it be vectorized:
>
> In [7]: def step(x):
>   ...:     return asarray(x>=0,dtype=float)
>   ...:
>
> In [8]: step(linspace(-1,1,9))
> Out[8]: array([ 0.,  0.,  0.,  0.,  1.,  1.,  1.,  1.,  1.])
>
> Though if you prefer step(0)==0.5 it's a bit of a pain.
>
> Anne
> _______________________________________________
> SciPy-user mailing list
> SciPy-user@scipy.org
> http://projects.scipy.org/mailman/listinfo/scipy-user
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://projects.scipy.org/pipermail/scipy-user/attachments/20070320/34416464/attachment.html 


More information about the SciPy-user mailing list