[docs] [issue23226] Add float linspace recipe to docs
Andrew Barnert
report at bugs.python.org
Wed Jan 14 07:45:55 CET 2015
Andrew Barnert added the comment:
So something like the first version below? Or should even the example be inline, as in the second version below? (Apologies if the formatting gets screwed up pasting from docs to bugs.)
---
Range objects are inappropriate for non-integral types, especially inexact types such as :class:`float`. In most cases, for such types, it is better to specify a count of numbers or intervals instead of a step size. For example:
>>> start, stop, num = 0, 10, 11
>>> step = (stop-start)/(num-1)
>>> [start + i*step for i in range(num)]
[0.0, 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0]
.. seealso::
* `linspace recipe <http://code.activestate.com/recipes/579000/>`_
for an example lazy sequence built on this algorithm, and links
to alternatives.
---
Range objects are inappropriate for non-integral types, especially inexact types such as :class:`float`. In most cases, it is better to specify a count of numbers or intervals instead of a step size, as in `[start + i*(stop-start)/(num-1) for i in range(num)]`.
.. seealso::
* `linspace recipe <http://code.activestate.com/recipes/579000/>`_
for an example lazy sequence built on this algorithm, and links
to alternatives.
----------
_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue23226>
_______________________________________
More information about the docs
mailing list