[Numpy-discussion] Warning: invalid value encountered in true_divide?

Robert Kern robert.kern at gmail.com
Wed Mar 30 13:19:24 EDT 2011

On Wed, Mar 30, 2011 at 12:12, Joon Ro <joonpyro at gmail.com> wrote:
> Hi,
> After numpy upgrade, I started to get "Warning: invalid value encountered in
> true_divide," when I run a code which did now show any warning previously.
> What does it mean and where should I look to fix this?

It means that a NaN popped up in a division somewhere. It always was
there, but some previous versions of numpy had the warnings
unintentionally silenced.

> It does not stop my
> debugger so I could not identify where the message was from.

You can use np.seterr() to change how these warnings are printed. In
particular, you can cause an exception to be raised so that you can
use a debugger to locate the source.


Robert Kern

"I have come to believe that the whole world is an enigma, a harmless
enigma that is made terrible by our own mad attempt to interpret it as
though it had an underlying truth."
  -- Umberto Eco

More information about the NumPy-Discussion mailing list