MCPcopy Create free account
hub / github.com/numpy/numpy / array_equal

Function array_equal

numpy/core/numeric.py:2379–2446  ·  view source on GitHub ↗

True if two arrays have the same shape and elements, False otherwise. Parameters ---------- a1, a2 : array_like Input arrays. equal_nan : bool Whether to compare NaN's as equal. If the dtype of a1 and a2 is complex, values will be considered equal if eit

(a1, a2, equal_nan=False)

Source from the content-addressed store, hash-verified

2377
2378@array_function_dispatch(_array_equal_dispatcher)
2379def array_equal(a1, a2, equal_nan=False):
2380 """
2381 True if two arrays have the same shape and elements, False otherwise.
2382
2383 Parameters
2384 ----------
2385 a1, a2 : array_like
2386 Input arrays.
2387 equal_nan : bool
2388 Whether to compare NaN's as equal. If the dtype of a1 and a2 is
2389 complex, values will be considered equal if either the real or the
2390 imaginary component of a given value is ``nan``.
2391
2392 .. versionadded:: 1.19.0
2393
2394 Returns
2395 -------
2396 b : bool
2397 Returns True if the arrays are equal.
2398
2399 See Also
2400 --------
2401 allclose: Returns True if two arrays are element-wise equal within a
2402 tolerance.
2403 array_equiv: Returns True if input arrays are shape consistent and all
2404 elements equal.
2405
2406 Examples
2407 --------
2408 >>> np.array_equal([1, 2], [1, 2])
2409 True
2410 >>> np.array_equal(np.array([1, 2]), np.array([1, 2]))
2411 True
2412 >>> np.array_equal([1, 2], [1, 2, 3])
2413 False
2414 >>> np.array_equal([1, 2], [1, 4])
2415 False
2416 >>> a = np.array([1, np.nan])
2417 >>> np.array_equal(a, a)
2418 False
2419 >>> np.array_equal(a, a, equal_nan=True)
2420 True
2421
2422 When ``equal_nan`` is True, complex values with nan components are
2423 considered equal if either the real *or* the imaginary components are nan.
2424
2425 >>> a = np.array([1 + 1j])
2426 >>> b = a.copy()
2427 >>> a.real = np.nan
2428 >>> b.imag = np.nan
2429 >>> np.array_equal(a, b, equal_nan=True)
2430 True
2431 """
2432 try:
2433 a1, a2 = asarray(a1), asarray(a2)
2434 except Exception:
2435 return False
2436 if a1.shape != a2.shape:

Callers

nothing calls this directly

Calls 3

isnanFunction · 0.85
asarrayFunction · 0.70
allMethod · 0.45

Tested by

no test coverage detected