This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: Add float linspace recipe to docs
Type: enhancement Stage:
Components: Documentation Versions: Python 3.5
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: rhettinger Nosy List: abarnert, docs@python, mark.dickinson, python-dev, rhettinger
Priority: normal Keywords: patch

Created on 2015-01-12 22:40 by abarnert, last changed 2022-04-11 14:58 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
stdtypes.rst.diff abarnert, 2015-01-12 22:40 Docs diff review
stdtypes.rst.diff abarnert, 2015-01-12 23:22 based on review review
Messages (5)
msg233893 - (view) Author: Andrew Barnert (abarnert) * Date: 2015-01-12 22:40
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).
msg233897 - (view) Author: Andrew Barnert (abarnert) * Date: 2015-01-12 23:22
As suggested by the review: removing unnecessary parenthetical, changing "ulp" to "digit", and fixing the recipe link.
msg234006 - (view) Author: Raymond Hettinger (rhettinger) * (Python committer) Date: 2015-01-14 05:48
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).
msg234009 - (view) Author: Andrew Barnert (abarnert) * Date: 2015-01-14 06:45
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.
msg274667 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2016-09-06 23:36
New changeset bb8fe61d78a4 by Raymond Hettinger in branch 'default':
Issue #23226:  Add linspace() recipe to the docs
https://hg.python.org/cpython/rev/bb8fe61d78a4
History
Date User Action Args
2022-04-11 14:58:11adminsetgithub: 67415
2016-09-06 23:36:31rhettingersetstatus: open -> closed
resolution: fixed
2016-09-06 23:36:06python-devsetnosy: + python-dev
messages: + msg274667
2015-01-14 16:11:52mark.dickinsonsetnosy: + mark.dickinson
2015-01-14 06:45:55abarnertsetmessages: + msg234009
2015-01-14 05:48:10rhettingersetassignee: docs@python -> rhettinger

messages: + msg234006
nosy: + rhettinger
2015-01-12 23:22:33abarnertsetfiles: + stdtypes.rst.diff

messages: + msg233897
2015-01-12 22:40:48abarnertcreate