summaryrefslogtreecommitdiff
path: root/scipy/base/function_base.py
diff options
context:
space:
mode:
authorcookedm <cookedm@localhost>2005-12-06 21:52:17 +0000
committercookedm <cookedm@localhost>2005-12-06 21:52:17 +0000
commitf487b5a30df5ce841cc2ddde91af6d5ea0fe2134 (patch)
tree3e288ba900608395a670d555fc8fdb19f47c1aa3 /scipy/base/function_base.py
parent6c30140dc13115f7c7b1e8df9bf5be79da57ca10 (diff)
downloadnumpy-f487b5a30df5ce841cc2ddde91af6d5ea0fe2134.tar.gz
More robust corner cases for linspace
Diffstat (limited to 'scipy/base/function_base.py')
-rw-r--r--scipy/base/function_base.py17
1 files changed, 11 insertions, 6 deletions
diff --git a/scipy/base/function_base.py b/scipy/base/function_base.py
index e3ff5f5c3..d6bb4d422 100644
--- a/scipy/base/function_base.py
+++ b/scipy/base/function_base.py
@@ -82,17 +82,22 @@ def logspace(start, stop, num=50, endpoint=True):
return _nx.power(10.0, y)
def linspace(start, stop, num=50, endpoint=True, retstep=False):
- """ Return 'num' evenly spaced samples from 'start' to 'stop'. If
- 'endpoint' is True, the last sample is 'stop'. If 'retstep' is
- True then return the step value used.
+ """Return evenly spaced numbers.
+
+ Return 'num' evenly spaced samples from 'start' to 'stop'. If
+ 'endpoint' is True, the last sample is 'stop'. If 'retstep' is
+ True then return the step value used.
"""
- if num <= 0: return array([])
+ num = int(num)
+ if num <= 0:
+ return array([])
if endpoint:
+ if num == 1:
+ return array([start])
step = (stop-start)/float((num-1))
- y = _nx.arange(0, num) * step + start
else:
step = (stop-start)/float(num)
- y = _nx.arange(0, num) * step + start
+ y = _nx.arange(0, num) * step + start
if retstep:
return y, step
else: