Return an array representation of self
Parameters: | attrs : list of tuple or None
|
---|---|
Returns: | dict of array
|
Notes
Attribute arrays are in index order such that TreeNode.id can be used as a lookup into the the array
If length is an attribute, this will also record the length off the root which is nan. Take care when summing.
Examples
>>> from six import StringIO
>>> from skbio import TreeNode
>>> t = TreeNode.read(StringIO('(((a:1,b:2,c:3)x:4,(d:5)y:6)z:7);'))
>>> res = t.to_array()
>>> res.keys()
['child_index', 'length', 'name', 'id_index', 'id']
>>> res['child_index']
[(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;
1 b:2.0;
2 c:3.0;
3 d:5.0;
4 (a:1.0,b:2.0,c:3.0)x:4.0;
5 (d:5.0)y:6.0;
6 ((a:1.0,b:2.0,c:3.0)x:4.0,(d:5.0)y:6.0)z:7.0;
7 (((a:1.0,b:2.0,c:3.0)x:4.0,(d:5.0)y:6.0)z:7.0);
>>> res['id']
array([0, 1, 2, 3, 4, 5, 6, 7])
>>> res['name']
array(['a', 'b', 'c', 'd', 'x', 'y', 'z', None], dtype=object)