# 两个向量是否相近-np.allclose

比较两个向量是否相同直接==就行，但是相近的话就不一样了，当然可以自己实现，这里numpy提供了方法，

官方API:<https://docs.scipy.org/doc/numpy/reference/generated/numpy.allclose.html>

```python
numpy.allclose(a, b, rtol=1e-05, atol=1e-08, equal_nan=False)
```

> a,b两个向量 a,b两个向量 rtol : float The relative tolerance parameter atol : float The absolute tolerance parameter equal\_nan : bool 是否匹配空nan值 return 是否相近

```python
>>> np.allclose([1e10,1e-7], [1.00001e10,1e-8])
False
>>> np.allclose([1e10,1e-8], [1.00001e10,1e-9])
True
>>> np.allclose([1e10,1e-8], [1.0001e10,1e-9])
False
>>> np.allclose([1.0, np.nan], [1.0, np.nan])
False
>>> np.allclose([1.0, np.nan], [1.0, np.nan], equal_nan=True)
True
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://im-qianuxn.gitbook.io/pytorch/ji-suan-ji/numpy-pandas-matplotlib/numpy/xian-dai/np-allclose.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
