[SciPy-user] possible to get INF in divide by zero ?

Ryan May rmay31@gmail....
Fri Aug 29 13:09:18 CDT 2008

Stef Mientki wrote:
> thank you all for the explanations.
> I'm a practical engineer, who almost never divide by zero.
> But the question came from my son,
> familiar with python and a little with scipy.
> After his first lesson in MatLab, he said:
> Oh what a beautiful environment is MatLab, it's even capable to divide 
> by zero without errors.
> So for the moment probably MatLab is better suited for educational purposes.


> I'll ask him again to compare scipy and Matlab, after a few weeks  ;-)

The fundamental difference here is that Matlab operates using double 
precision numbers for *everything* by default.  I personally consider 
that a design flaw.  Numpy is being smart and letting you use integers 
if that's what you give it.  So this isn't some limitation of numpy, 
it's just a slight difference of "opinion" between the packages.  Numpy 
is capable of the same behavior with just one of two minor tweaks to the 

 >>>a = np.array([2., 3.]) #Note the decimal points, this makes floats
array([ Inf,  Inf])


 >>>a = np.array([2, 3], dtype=np.float32) #Explicitly ask for floats
array([ Inf,  Inf], dtype=float32)


Ryan May
Graduate Research Assistant
School of Meteorology
University of Oklahoma

More information about the SciPy-user mailing list