search
Search
Unlock 100+ guides
search toc
close
Cancel
Post
account_circle
Profile
exit_to_app
Sign out
What does this mean?
Why is this true?
Give me some examples!
search
keyboard_voice
close
Searching Tips
Search for a recipe:
"Creating a table in MySQL"
Search for an API documentation: "@append"
Search for code: "!dataframe"
Apply a tag filter: "#python"
Useful Shortcuts
/ to open search panel
Esc to close search panel
to navigate between search results
d to clear all current filters
Enter to expand content preview
Doc Search
Code Search Beta
SORRY NOTHING FOUND!
mic
Start speaking...
Voice search is only supported in Safari and Chrome.
Shrink
Navigate to

# NumPy | isclose method

schedule Aug 12, 2023
Last updated
local_offer
PythonNumPy
Tags
mode_heat
Master the mathematics behind data science with 100+ top-tier guides
Start your free 7-days trial now!

Numpy's `isclose(~)` performs an element-wise comparison given two arrays, and for each comparison, returns True if the difference between the two values falls within the specified tolerance.

# Parameters

1. `x1` | `array-like`

The first input array.

2. `x2` | `array-like`

The second input array.

3. `rtol` | `float` | `optional`

The relative tolerance parameter. By default, `rtol=0`.

4. `atol` | `float` | `optional`

The absolute tolerance parameter. By default, `atol` is set to a small number `(~1e-8)`, and is thus not suitable when comparing numbers that are far smaller than 1.

5. `equal_nan` | `boolean` | `optional`

If True, then element-wise comparisons that involve two NaNs will evaluate to True. By default, `equal_nan=False`.

Here, the element-wise comparison evaluates to True if:

``` absolute(a - b) <= (atol + rtol * absolute(b)) ```

# Return value

A single boolean that indicates whether or not two arrays are "close" enough.

# Examples

## Basic usage

``` np.isclose([1,2], [3,2]) array([False, True]) ```

Here, the first element-wise comparison `2 != 5`, so the method returns `False`.

## Specifying an absolute tolerance parameter

``` np.isclose([6,4], [8,3], atol=2) array([ True, True]) ```

Here, `absolute(6,8) <= 2` and `absolute(4,3) <= 2`.

## Specifying a relative tolerance parameter

``` np.isclose([6,3], [4,6], rtol=0.5) array([ True, True]) ```

Here, `absolute(6,4) <= 4*0.5` and `absolute(3,6) <= 6*0.5`.

## Comparing NaNs

``` np.isclose(np.NaN, np.NaN) False `````` np.isclose(np.NaN, np.NaN, equal_nan=True) True ```
Edited by 0 others
thumb_up
thumb_down
Comment
Citation
Ask a question or leave a feedback...
thumb_up
0
thumb_down
0
chat_bubble_outline
0
settings
Enjoy our search
Hit / to insta-search docs and recipes!