diff options
author | Charles Harris <charlesr.harris@gmail.com> | 2017-06-18 10:27:35 -0600 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-06-18 10:27:35 -0600 |
commit | 1d9189e5de35c8a0a31dd219e4dced96a4bd9ee9 (patch) | |
tree | ff4f8c55e8d3bf28774788de236894e53377d303 /numpy/lib/function_base.py | |
parent | 3ff00b18661a0106c91177c87f0a137994a62f3a (diff) | |
parent | 47242a25920e72366e906a7ffaa2fb41144623d3 (diff) | |
download | numpy-1d9189e5de35c8a0a31dd219e4dced96a4bd9ee9.tar.gz |
Merge pull request #9259 from soupault/fix_9251
MAINT: Use XOR for bool arrays in `np.diff`
Diffstat (limited to 'numpy/lib/function_base.py')
-rw-r--r-- | numpy/lib/function_base.py | 14 |
1 files changed, 9 insertions, 5 deletions
diff --git a/numpy/lib/function_base.py b/numpy/lib/function_base.py index 4739b2176..a3db3494c 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 |