[SciPy-user] how to make a sinc(x) function - "divide by zero" !

Sebastian Haase haase at msg.ucsf.edu
Mon Dec 12 12:26:34 CST 2005


Thanks Perry, 

that's the answer I hoped for ;-)  
I was using something like CVS numarray - around 1.3 ; 
>>> na.__version__
'1.4.0'
(na.array  has not dtype argument yet...)

but now it works !!??  (Maybe the errorMode stack got messed up when I was 
playing with it !)

- Sebastian

On Monday 12 December 2005 10:13, Perry Greenfield wrote:
> On Dec 12, 2005, at 12:32 PM, Sebastian Haase wrote:
> > Hi,
> > I was trying to implement a "sinc" [sin(x)/x] in numarray. But the
> > "where"-semantics makes it choke on the x=0: 0/0 case.
> > (This should of course work for x being an array - so "if" is no
> > option)
> > The best I could come up with was:
> >
> > def sinc(r):
> >     na.Error.pushMode(all="ignore")
> >     a = na.where(r, na.divide(na.sin(r),r), 1)
> >     na.Error.popMode()
> >     return a
> >
> > but I still seem to get  a warning...
> >
> >>>> F.sinc(0)
> >
> > Warning: Encountered invalid numeric result(s)  in divide
> > 1.0
> >
> > What is a better way of doing this ?
> > Thanks,
> > Sebastian Haase
>
> That's odd. When I try your example it prints 1 without any warning.
> What version and platform are you running on?

>
> Thanks, Perry
>
> _______________________________________________
> SciPy-user mailing list
> SciPy-user at scipy.net
> http://www.scipy.net/mailman/listinfo/scipy-user



More information about the SciPy-user mailing list