cf.equals

cf.equals(x, y, rtol=None, atol=None)

Ascertain if two objects are equal using numerically tolerant equality where appropiate.

If the first argument (x) has an equals method, then it is used. In this case equals(x,y) is equivalent to x.equals(y).

Parameters:
  • x (object) – The left hand side of the comparison.
  • y (object) – The right hand side of the comparison.
  • atol (None or float) – Optional. If None then use the default method for setting the absolute tolerance for numerical equality (refer to cf for details). If a number then set the absolute tolerance to this value for all such comparisons.
  • rtolOptional. If None then use the default method for setting the relative tolerance for numerical equality (refer to cf for details). If a number then set the relative tolerance to this value for all such comparisons.
Returns:

True or False.

Examples

>>> x
<CF Field: rain(10,20)>
>>> cf.equals(x,x)
True
>>> cf.equals(1.0, 1.0)
True
>>> cf.equals(1.0, 33)
False
>>> cf.equals('a', 'a')
True
>>> cf.equals('a', 'b')
False
>>> type(x), x.dtype
(<type 'numpy.ndarray'>, dtype('int64'))
>>> y=x.copy()
>>> cf.equals(x, y)
True
>>> cf.equals(x, x+1)
False
>>> class A(object): pass
>>> a=A()
>>> b=A()
>>> cf.equals(a, a)
True
>>> cf.equals(a, b)
False

Previous topic

cf.eq

Next topic

cf.ge

This Page