diff options
author | Eric Wieser <wieser.eric@gmail.com> | 2017-07-13 12:40:32 +0100 |
---|---|---|
committer | Eric Wieser <wieser.eric@gmail.com> | 2017-07-13 13:02:51 +0100 |
commit | 2bfec2c0dd92958694e6d736530ae6333d7d62d7 (patch) | |
tree | 0af7b27c6432619c8752bd33fe1754d2ed140612 /numpy/lib/function_base.py | |
parent | d86e3fee3c9906ce0fad36520de86d9ac306cee8 (diff) | |
download | numpy-2bfec2c0dd92958694e6d736530ae6333d7d62d7.tar.gz |
BUG: Only allow 1d distance arrays
2d arrays would work, but in unpredictable and undocumented ways.
This at least makes gh-9401 give a better error message.
Diffstat (limited to 'numpy/lib/function_base.py')
-rw-r--r-- | numpy/lib/function_base.py | 4 |
1 files changed, 3 insertions, 1 deletions
diff --git a/numpy/lib/function_base.py b/numpy/lib/function_base.py index 989030e03..91e7dc616 100644 --- a/numpy/lib/function_base.py +++ b/numpy/lib/function_base.py @@ -1697,8 +1697,10 @@ def gradient(f, *varargs, **kwargs): for i, distances in enumerate(dx): if distances.ndim == 0: continue + elif distances.ndim != 1: + raise ValueError("distances must be either scalars or 1d") if len(distances) != f.shape[axes[i]]: - raise ValueError("distances must be either scalars or match " + raise ValueError("when 1d, distances must match " "the length of the corresponding dimension") diffx = np.diff(dx[i]) # if distances are constant reduce to the scalar case |