From 0bf437fb0ae42fefdb0040692b993f17dedb2e3d Mon Sep 17 00:00:00 2001 From: Egor Panfilov Date: Sat, 17 Jun 2017 15:11:06 +0300 Subject: BUG: Switched to xor for bool arrays in diff, added corresponding tests --- numpy/lib/function_base.py | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) (limited to 'numpy/lib/function_base.py') diff --git a/numpy/lib/function_base.py b/numpy/lib/function_base.py index 4739b2176..f37d79663 100644 --- a/numpy/lib/function_base.py +++ b/numpy/lib/function_base.py @@ -1,7 +1,6 @@ from __future__ import division, absolute_import, print_function import collections -import operator import re import sys import warnings @@ -1912,10 +1911,16 @@ def diff(a, n=1, axis=-1): slice2[axis] = slice(None, -1) slice1 = tuple(slice1) slice2 = tuple(slice2) + + if a.dtype == np.bool_: + da = a[slice1] ^ a[slice2] + else: + da = a[slice1] - a[slice2] + if n > 1: - return diff(a[slice1]-a[slice2], n-1, axis=axis) + return diff(da, n-1, axis=axis) else: - return a[slice1]-a[slice2] + return da def interp(x, xp, fp, left=None, right=None, period=None): @@ -2061,6 +2066,7 @@ def interp(x, xp, fp, left=None, right=None, period=None): else: return interp_func(x, xp, fp, left, right).item() + def angle(z, deg=0): """ Return the angle of the complex argument. @@ -2083,8 +2089,6 @@ def angle(z, deg=0): arctan2 absolute - - Examples -------- >>> np.angle([1.0, 1.0j, 1+1j]) # in radians -- cgit v1.2.1 From 47242a25920e72366e906a7ffaa2fb41144623d3 Mon Sep 17 00:00:00 2001 From: Egor Panfilov Date: Sat, 17 Jun 2017 23:31:54 +0300 Subject: MAINT: Use neq instead of xor in diff --- numpy/lib/function_base.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'numpy/lib/function_base.py') diff --git a/numpy/lib/function_base.py b/numpy/lib/function_base.py index f37d79663..a3db3494c 100644 --- a/numpy/lib/function_base.py +++ b/numpy/lib/function_base.py @@ -1913,7 +1913,7 @@ def diff(a, n=1, axis=-1): slice2 = tuple(slice2) if a.dtype == np.bool_: - da = a[slice1] ^ a[slice2] + da = a[slice1] != a[slice2] else: da = a[slice1] - a[slice2] -- cgit v1.2.1