larray.Session.element_equals
- Session.element_equals(other, rtol=0, atol=0, nans_equal=False) Array [source]
Test if each element (group, axis and array) of the current session equals the corresponding element of another session.
For arrays, it is equivalent to apply
Array.equals()
with flag nans_equal=True to all arrays from two sessions.- Parameters
- otherSession
Session to compare with.
- 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 True.
- Returns
- Boolean Array
See also
Notes
Metadata is ignored.
For finite values, element_equals uses the following equation to test whether two arrays are equal:
absolute(array1 - array2) <= (atol + rtol * absolute(array2))
Examples
>>> a = Axis('a=a0..a2') >>> a01 = a['a0,a1'] >> 'a01' >>> s1 = Session({'a': a, 'a01': a01, 'arr1': ndtest(2), 'arr2': ndtest((2, 2))}) >>> s2 = Session({'a': a, 'a01': a01, 'arr1': ndtest(2), 'arr2': ndtest((2, 2))})
Identical sessions
>>> s1.element_equals(s2) name a a01 arr1 arr2 True True True True
Different value(s) between two arrays
>>> s2.arr1['a1'] = 0 >>> s1.element_equals(s2) name a a01 arr1 arr2 True True False True
Test equality between two arrays within a given tolerance range. Return True if absolute(s1.arr1 - s2.arr1) <= (atol + rtol * absolute(s2.arr1)).
>>> s1.arr1 = Array([6., 8.], "a=a0,a1") >>> s2.arr1 = Array([5.999, 8.001], "a=a0,a1")
>>> s1.element_equals(s2) name a a01 arr1 arr2 True True False True >>> s1.element_equals(s2, atol=0.01) name a a01 arr1 arr2 True True True True >>> s1.element_equals(s2, rtol=0.01) name a a01 arr1 arr2 True True True True
Different label(s)
>>> s2.arr2 = ndtest("b=b0,b1; a=a0,a1") >>> s2.a = Axis('a=a0,a1') >>> s1.element_equals(s2) name a a01 arr1 arr2 False True False False
Extra/missing objects
>>> s2.arr3 = ndtest((3, 3)) >>> del s2.a >>> s1.element_equals(s2) name a a01 arr1 arr2 arr3 False True False False False