A simple binary tree in which look-ups return the value of the
closest leaf. Only float objects are supported for the keys and
values. Look-ups raise KeyError if the tree is empty.
Example:
>>> x = NearestLeafTree()
>>> x[100.0] = 120.
>>> x[104.0] = 100.
>>> x[102.0] = 110.
>>> x[90.]
120.0
>>> x[100.999]
120.0
>>> x[101.001]
110.0
>>> x[200.]
100.0
>>> del x[104]
>>> x[200.]
110.0
>>> x.keys()
[100.0, 102.0]
>>> 102 in x
True
>>> 103 in x
False
>>> x.to_xml(u"H1").write()
<Array Type="real_8" Name="H1:nearestleaftree:array">
<Dim>2</Dim>
<Dim>2</Dim>
<Stream Delimiter=" " Type="Local">
100 102
120 110
</Stream>
</Array>
Definition at line 369 of file far.py.
def far.NearestLeafTree.__init__ |
( |
|
self, |
|
|
|
items = () |
|
) |
| |
Initialize a NearestLeafTree.
Example:
>>> x = NearestLeafTree()
>>> x = NearestLeafTree([(100., 120.), (104., 100.), (102., 110.)])
>>> y = {100.: 120., 104.: 100., 102.: 100.}
>>> x = NearestLeafTree(y.items())
Definition at line 408 of file far.py.
def far.NearestLeafTree.__delitem__ |
( |
|
self, |
|
|
|
x |
|
) |
| |
Example:
>>> x = NearestLeafTree([(100., 0.), (150., 1.), (200., 0.)])
>>> del x[150.]
>>> x
NearestLeafTree([(100., 0.), (200., 0.)])
>>> del x[:]
NearestLeafTree([])
Definition at line 479 of file far.py.