larray.Array.eq
- Array.eq(other, rtol=0, atol=0, nans_equal=False) Array [source]
Compare this array with another array element-wise and returns an array of booleans.
- Parameters
- otherArray-like
Input array. asarray() is used on a non-Array input.
- rtolfloat or int, optional
The relative tolerance parameter (see Notes). Defaults to 0.
- atolfloat or int, optional
The absolute tolerance parameter (see Notes). Defaults to 0.
- nans_equalboolean, optional
Whether to consider Nan values at the same positions in the two arrays as equal. By default, an array containing NaN values is never equal to another array, even if that other array also contains NaN values at the same positions. The reason is that a NaN value is different from anything, including itself. Defaults to False.
- Returns
- Array
Boolean array where each cell tells whether corresponding elements of this array and other are equal within a tolerance range if given. If nans_equal=True, corresponding elements with NaN values will be considered as equal.
See also
Array.equals
,Array.isclose
Notes
For finite values, eq uses the following equation to test whether two values are equal:
absolute(array1 - array2) <= (atol + rtol * absolute(array2))
The above equation is not symmetric in array1 and array2, so that array1.eq(array2) might be different from array2.eq(array1) in some rare cases.
Examples
>>> arr1 = Array([6., np.nan, 8.], "a=a0..a2") >>> arr1 a a0 a1 a2 6.0 nan 8.0
Default behavior (same as == operator)
>>> arr1.eq(arr1) a a0 a1 a2 True False True
Test equality between two arrays within a given tolerance range. Return True if absolute(array1 - array2) <= (atol + rtol * absolute(array2)).
>>> arr2 = Array([5.999, np.nan, 8.001], "a=a0..a2") >>> arr2 a a0 a1 a2 5.999 nan 8.001 >>> arr1.eq(arr2, nans_equal=True) a a0 a1 a2 False True False >>> arr1.eq(arr2, atol=0.01, nans_equal=True) a a0 a1 a2 True True True >>> arr1.eq(arr2, rtol=0.01, nans_equal=True) a a0 a1 a2 True True True