Hi,
I am wondering a bit about the the behaviour of logspace:
Definition: numpy.logspace(start, stop, num=50, endpoint=True, base=10.0)
Reading this I would assume that
numpy.logspace(10**-12, 0.0, 100)
gives 100 values, from start=10**-12 to stop=0.0,
equispaced on a logarithmic scale.
But this is not the case.
Instead one has to do:
numpy.logspace(-12, 0.0, 100)
Docstring:
Evenly spaced numbers on a logarithmic scale.
Computes int(num) evenly spaced exponents from start to stop.
If endpoint=True, then last exponent is stop.
Returns base**exponents.
My impression is that only the very last line is clearly
saying what logspace does.
And of course the code itself:
y = linspace(start,stop,num=num,endpoint=endpoint)
return _nx.power(base,y)
Possible solutions (see below):
a) modify logspace so that numpy.logspace(10**-12, 0.0, 100) works
b) keep the current behaviour and improve the doc-string
I would be interested in opinions on this.
Best, Arnd
Possible solution for (a) (no error checking yet):
def logspace_modified(start, stop, num=50, endpoint=True):
"""Evenly spaced numbers on a logarithmic scale.
Computes `num` evenly spaced numbers on a logarithmic scale
from `start` to `stop`.
If endpoint=True, then last exponent is `stop`.
"""
lstart = log(start)
lstop = log(stop)
y = linspace(lstart, lstop, num=num, endpoint=endpoint)
return exp(y)
Possible improvent of the doc-string (b) - due to Lars Bittrich:
def logspace(start,stop,num=50,endpoint=True,base=10.0):
"""Evenly spaced numbers on a logarithmic scale.
Return 'int(num)' evenly spaced samples on a logarithmic scale from
'base'**'start' to 'base'**'stop'. If 'endpoint' is True, the
last sample is 'base'**'stop'."""