Bases: object
Create an object for storing a comparison expression.
A comparison expression comprises a relation (such as ‘less than’) and a value (any object capable of being related to with the standard comparison operators). These are stored in the relation and value attributes respectively.
The comparison is evaluated for an arbitrary object with the evaluate method.
Valid relations are:
Relation | Description |
---|---|
lt | Strictly less than |
le | Less than or equal |
gt | Strictly greater than |
ge | Greater than or equal |
eq | Equals (within a tolerance) |
ne | Not equal to (within a tolerance) |
inside | Inside a given range (range bounds included) |
outside | Outside a given range (range bounds excluded) |
See also
As a convenience, for each relation in the above list there is an identically named function which returns the appropriate Comparison object.
Examples
>>> c = cf.Comparison('le', 5)
>>> c.evaluate(4)
True
>>> c.evaluate(5)
True
>>> c = lt(5)
>>> c.evaluate(4)
True
>>> c = cf.Comparison('inside', (1,2))
>>> a = numpy.arange(4)
>>> c.evaluate(a)
array([False, True, True, False], dtype=bool)
>>> (a >= 1) & (a <= 2)
array([False, True, True, False], dtype=bool)
Initialization
Parameters : |
|
---|
Return a deep copy.
Examples
>>> c.copy()
Return a string containing a full description of the object.
Parameters: |
|
---|---|
Returns: | A string containing the description. |
See also
Evaluate the comparison expression for a given object.
Parameters : |
|
---|---|
Returns : |
|
Examples
>>> c = cf.Comparison('lt', 5.5)
>>> c.evaluate(6)
False
>>> c = cf.Comparison('inside', (1,2))
>>> array = numpy.arange(4)
>>> array
array([0, 1, 2, 3])
>>> c.evaluate(array)
array([False, True, True, False], dtype=bool)