From e77b7b98df233f72a9d50934a4bf5b93c163b482 Mon Sep 17 00:00:00 2001 From: John Kirkham Date: Thu, 21 Jan 2016 13:24:59 -0500 Subject: BUG: In `norm`, always cast non-floating point arrays to 64-bit floats. Otherwise, weird integer roundoff errors give faulty results in some cases. --- numpy/linalg/linalg.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/numpy/linalg/linalg.py b/numpy/linalg/linalg.py index 9dc879d31..fe2031efb 100644 --- a/numpy/linalg/linalg.py +++ b/numpy/linalg/linalg.py @@ -2112,6 +2112,9 @@ def norm(x, ord=None, axis=None, keepdims=False): """ x = asarray(x) + if not issubclass(x.dtype.type, inexact): + x = x.astype(float) + # Immediately handle some default, simple, fast, and common cases. if axis is None: ndim = x.ndim -- cgit v1.2.1