larray.LArray.eq

LArray.eq(self, other, rtol=0, atol=0, nans_equal=False)[source]

Compares self with another array element-wise and returns an array of booleans.

Parameters
otherLArray-like

Input array. aslarray() is used on a non-LArray 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 or not 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
LArray

Boolean array where each cell tells whether corresponding elements of self 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

LArray.equals

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 = LArray([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 = LArray([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