Skip to content

Commit 816fd7c

Browse files
Update documentation for floating-point precision and determinant calculations (numpy#27602)
* Update basics.types.rst: Clarify determinant precision handling This update adds clarification to the section on numerical data types regarding the precision of matrix determinants in NumPy. A note has been included explaining that results close to zero, such as those from the determinant of the matrix np.array([[5,5,6],[7,7,5],[4,4,8]]), can appear as very small negative numbers due to floating-point precision issues. Additionally, a reference to the `np.isclose()` function has been added to guide users on checking if a value is close to zero, which can help mitigate confusion regarding the expected result of zero for certain matrix determinants. * Update basics.types.rst: Clarify determinant precision handling This update adds clarification to the section on numerical data types regarding the precision of matrix determinants in NumPy. A note has been included explaining that results close to zero, such as those from the determinant of the matrix np.array([[5,5,6],[7,7,5],[4,4,8]]), can appear as very small negative numbers due to floating-point precision issues. Additionally, a reference to the `np.isclose()` function has been added to guide users on checking if a value is close to zero, which can help mitigate confusion regarding the expected result of zero for certain matrix determinants. * Update basics.types.rst: Clarify determinant precision handling This update adds clarification to the section on numerical data types regarding the precision of matrix determinants in NumPy. A note has been included explaining that results close to zero, such as those from the determinant of the matrix np.array([[5,5,6],[7,7,5],[4,4,8]]), can appear as very small negative numbers due to floating-point precision issues. Additionally, a reference to the `np.isclose()` function has been added to guide users on checking if a value is close to zero, which can help mitigate confusion regarding the expected result of zero for certain matrix determinants. * Update basics.types.rst: Clarify determinant precision handling This update adds clarification to the section on numerical data types regarding the precision of matrix determinants in NumPy. A note has been included explaining that results close to zero, such as those from the determinant of the matrix np.array([[5,5,6],[7,7,5],[4,4,8]]), can appear as very small negative numbers due to floating-point precision issues. Additionally, a reference to the `np.isclose()` function has been added to guide users on checking if a value is close to zero, which can help mitigate confusion regarding the expected result of zero for certain matrix determinants. * Update basics.types.rst: Clarify determinant precision handling This update adds clarification to the section on numerical data types regarding the precision of matrix determinants in NumPy. A note has been included explaining that results close to zero, such as those from the determinant of the matrix np.array([[5,5,6],[7,7,5],[4,4,8]]), can appear as very small negative numbers due to floating-point precision issues. Additionally, a reference to the `np.isclose()` function has been added to guide users on checking if a value is close to zero, which can help mitigate confusion regarding the expected result of zero for certain matrix determinants. * Update basics.types.rst: Clarify determinant precision handling This update adds clarification to the section on numerical data types regarding the precision of matrix determinants in NumPy. A note has been included explaining that results close to zero, such as those from the determinant of the matrix np.array([[5,5,6],[7,7,5],[4,4,8]]), can appear as very small negative numbers due to floating-point precision issues. Additionally, a reference to the `np.isclose()` function has been added to guide users on checking if a value is close to zero, which can help mitigate confusion regarding the expected result of zero for certain matrix determinants. * Update basics.types.rst: Clarify determinant precision handling This update adds clarification to the section on numerical data types regarding the precision of matrix determinants in NumPy. A note has been included explaining that results close to zero, such as those from the determinant of the matrix np.array([[5,5,6],[7,7,5],[4,4,8]]), can appear as very small negative numbers due to floating-point precision issues. Additionally, a reference to the `np.isclose()` function has been added to guide users on checking if a value is close to zero, which can help mitigate confusion regarding the expected result of zero for certain matrix determinants. * Updating basics.types.rst: Clarify precision handling and link to floating point arithmetic reference. [skip azp][skip actions][skip cirrus] Updating basics.types.rst: - Reflowed text to adhere to the 88-column limit for better readability. - Added a link to an external resource for further information on floating-point arithmetic. [skip azp][skip actions][skip cirrus] * Updating basics.types.rst: Clarify precision handling and link to floating point arithmetic reference. [skip azp][skip actions][skip cirrus] Updating basics.types.rst: - Reflowed text to adhere to the 88-column limit for better readability. - Added a link to an external resource for further information on floating-point arithmetic. [skip azp][skip actions][skip cirrus] * Update basics.types.rst: Added a new section "Floating-point precision". [skip azp][skip actions][skip cirrus] - Moved the floating-point precision details into a new dedicated section titled "Floating Point Precision" for better discoverability. - Reflowed text to adhere to the 88-column limit for readability. - Added a link to an external resource on floating-point arithmetic for users seeking more detailed information. [skip azp][skip actions][skip cirrus] * Update doc/source/user/basics.types.rst: Update floating-point precision section for clarity.[skip azp][skip actions][skip cirrus] - Updated the description of floating-point behavior for improved clarity. - Changed phrasing from "a known behavior of floating-point operations in numerical libraries" to "a behavior common to all frameworks that use floating point arithmetic." [skip azp][skip actions][skip cirrus] Co-authored-by: Jake Vanderplas <[email protected]> * Update floating-point precision section: Replaced np.isclose() with np.linalg.cond() - Replaced the usage of np.isclose() with np.linalg.cond() to assess matrix stability. - Cond function provides a more accurate measure of how close a matrix is to being singular. * Update floating-point precision section: Replaced np.isclose() with np.linalg.cond() [skip azp][skip actions][skip cirrus] - Replaced the usage of np.isclose() with np.linalg.cond() to assess matrix stability. - Cond function provides a more accurate measure of how close a matrix is to being singular. [skip azp][skip actions][skip cirrus] * Simplified floating-point precision example by removing determinant and adding basic arithmetic case. [skip azp][skip actions][skip cirrus] - Removed the matrix determinant example to keep the focus on the general floating-point arithmetic issue. - Replaced with an example that illustrates floating-point precision in basic arithmetic. - Added explanation to make the topic more accessible for new users. [skip azp][skip actions][skip cirrus] --------- Co-authored-by: Jake Vanderplas <[email protected]>
1 parent 8c2476b commit 816fd7c

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

doc/source/user/basics.types.rst

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -342,6 +342,30 @@ range of possible values.
342342
>>> np.power(100, 100, dtype=np.float64)
343343
1e+200
344344

345+
Floating point precision
346+
========================
347+
348+
Many functions in NumPy, especially those in `numpy.linalg`, involve floating-point
349+
arithmetic, which can introduce small inaccuracies due to the way computers
350+
represent decimal numbers. For instance, when performing basic arithmetic operations
351+
involving floating-point numbers:
352+
353+
>>> 0.3 - 0.2 - 0.1 # This does not equal 0 due to floating-point precision
354+
-2.7755575615628914e-17
355+
356+
To handle such cases, it's advisable to use functions like `np.isclose` to compare
357+
values, rather than checking for exact equality:
358+
359+
>>> np.isclose(0.3 - 0.2 - 0.1, 0, rtol=1e-05) # Check for closeness to 0
360+
True
361+
362+
In this example, `np.isclose` accounts for the minor inaccuracies that occur in
363+
floating-point calculations by applying a relative tolerance, ensuring that results
364+
within a small threshold are considered close.
365+
366+
For information about precision in calculations, see `Floating-Point Arithmetic <https://docs.oracle.com/cd/E19957-01/806-3568/ncg_goldberg.html>`_.
367+
368+
345369
Extended precision
346370
==================
347371

0 commit comments

Comments
 (0)