TreeNode.
to_array
(attrs=None, nan_length_value=None)[source]¶Return an array representation of self
State: Experimental as of 0.4.0.
Parameters: |
|
---|---|
Returns: |
|
Return type: | dict of array |
Notes
Attribute arrays are in index order such that TreeNode.id can be used as a lookup into the array.
Examples
>>> from pprint import pprint
>>> from skbio import TreeNode
>>> t = TreeNode.read(['(((a:1,b:2,c:3)x:4,(d:5)y:6)z:7);'])
>>> res = t.to_array()
>>> sorted(res.keys())
['child_index', 'id', 'id_index', 'length', 'name']
>>> res['child_index']
array([[4, 0, 2],
[5, 3, 3],
[6, 4, 5],
[7, 6, 6]])
>>> for k, v in res['id_index'].items():
... print(k, v)
...
0 a:1.0;
<BLANKLINE>
1 b:2.0;
<BLANKLINE>
2 c:3.0;
<BLANKLINE>
3 d:5.0;
<BLANKLINE>
4 (a:1.0,b:2.0,c:3.0)x:4.0;
<BLANKLINE>
5 (d:5.0)y:6.0;
<BLANKLINE>
6 ((a:1.0,b:2.0,c:3.0)x:4.0,(d:5.0)y:6.0)z:7.0;
<BLANKLINE>
7 (((a:1.0,b:2.0,c:3.0)x:4.0,(d:5.0)y:6.0)z:7.0);
<BLANKLINE>
>>> res['id']
array([0, 1, 2, 3, 4, 5, 6, 7])
>>> res['name']
array(['a', 'b', 'c', 'd', 'x', 'y', 'z', None], dtype=object)