[issue23226] Add float linspace recipe to docs
New submission from Andrew Barnert: In a recent thread on python-ideas (https://mail.python.org/pipermail/python-ideas/2015-January/030817.html), it was concluded that Python should not have a range-like type for floats in the stdlib, but there should be some simple discussion of the alternatives in the docs. The attached diff describes the issues, demonstrates the simplest reasonable algorithm, and links to a recipe on ActiveState (which builds the same algorithm into a lazy sequence, and links to other recipes with different alternatives). ---------- assignee: docs@python components: Documentation files: stdtypes.rst.diff keywords: patch messages: 233893 nosy: abarnert, docs@python priority: normal severity: normal status: open title: Add float linspace recipe to docs type: enhancement versions: Python 3.5 Added file: http://bugs.python.org/file37684/stdtypes.rst.diff _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue23226> _______________________________________
Andrew Barnert added the comment: As suggested by the review: removing unnecessary parenthetical, changing "ulp" to "digit", and fixing the recipe link. ---------- Added file: http://bugs.python.org/file37685/stdtypes.rst.diff _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue23226> _______________________________________
Raymond Hettinger added the comment: This is too much. Try for a brief reference. This section of the docs is primarily about how range() works. Linspace() is at best a tangential discussion and shouldn't interfere with the usability of range() docs (a tool we actually have and that is in common use). ---------- assignee: docs@python -> rhettinger nosy: +rhettinger _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue23226> _______________________________________
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@bugs.python.org> <http://bugs.python.org/issue23226> _______________________________________
Changes by Mark Dickinson <dickinsm@gmail.com>: ---------- nosy: +mark.dickinson _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue23226> _______________________________________
Roundup Robot added the comment: New changeset bb8fe61d78a4 by Raymond Hettinger in branch 'default': Issue #23226: Add linspace() recipe to the docs https://hg.python.org/cpython/rev/bb8fe61d78a4 ---------- nosy: +python-dev _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue23226> _______________________________________
Changes by Raymond Hettinger <raymond.hettinger@gmail.com>: ---------- resolution: -> fixed status: open -> closed _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue23226> _______________________________________
participants (4)
-
Andrew Barnert
-
Mark Dickinson
-
Raymond Hettinger
-
Roundup Robot