diff options
author | David Zwicker <david.zwicker@ds.mpg.de> | 2019-11-21 18:18:19 +0100 |
---|---|---|
committer | Warren Weckesser <warren.weckesser@gmail.com> | 2019-11-21 12:18:19 -0500 |
commit | 8efd1e70a7789befc7a85a0b52254c68f7ae408a (patch) | |
tree | b9f62e89a0aa3d462f2fa2d0a41a2000b59488ef /numpy/core/function_base.py | |
parent | d428127183d46b2fbd99afefa4670642addf8d6e (diff) | |
download | numpy-8efd1e70a7789befc7a85a0b52254c68f7ae408a.tar.gz |
BUG: Fix step returned by linspace when num=1 and endpoint=False (#14929)
Changed the the behavior of linspace to return a proper step size for arguments num=1 and endpoint=False, where previously NaN was returned.
closes gh-14927
Diffstat (limited to 'numpy/core/function_base.py')
-rw-r--r-- | numpy/core/function_base.py | 5 |
1 files changed, 3 insertions, 2 deletions
diff --git a/numpy/core/function_base.py b/numpy/core/function_base.py index 42604ec3f..538ac8b84 100644 --- a/numpy/core/function_base.py +++ b/numpy/core/function_base.py @@ -139,7 +139,7 @@ def linspace(start, stop, num=50, endpoint=True, retstep=False, dtype=None, # from overriding what class is produced, and thus prevents, e.g. use of Quantities, # see gh-7142. Hence, we multiply in place only for standard scalar types. _mult_inplace = _nx.isscalar(delta) - if num > 1: + if div > 0: step = delta / div if _nx.any(step == 0): # Special handling for denormal numbers, gh-5437 @@ -154,7 +154,8 @@ def linspace(start, stop, num=50, endpoint=True, retstep=False, dtype=None, else: y = y * step else: - # 0 and 1 item long sequences have an undefined step + # sequences with 0 items or 1 item with endpoint=True (i.e. div <= 0) + # have an undefined step step = NaN # Multiply with delta to allow possible override of output class. y = y * delta |