@@ -335,9 +335,8 @@ def tree2rec(tree,
335335def array2tree (arr , name = 'tree' , tree = None ):
336336 """Convert a numpy structured array into a ROOT TTree.
337337
338- .. warning::
339- This function is experimental. Please report problems.
340- Not all data types are supported (``np.object`` and ``np.float16``).
338+ Fields of basic types, strings, and fixed-size subarrays of basic types are
339+ supported. ``np.object`` and ``np.float16`` are currently not supported.
341340
342341 Parameters
343342 ----------
@@ -359,6 +358,26 @@ def array2tree(arr, name='tree', tree=None):
359358 --------
360359 array2root
361360
361+ Examples
362+ --------
363+
364+ >>> from root_numpy import array2tree
365+ >>> import numpy as np
366+ >>>
367+ >>> a = np.array([(1, 2.5, 3.4),
368+ ... (4, 5, 6.8)],
369+ ... dtype=[('a', np.int32),
370+ ... ('b', np.float32),
371+ ... ('c', np.float64)])
372+ >>> tree = array2tree(a)
373+ >>> tree.Scan()
374+ ************************************************
375+ * Row * a * b * c *
376+ ************************************************
377+ * 0 * 1 * 2.5 * 3.4 *
378+ * 1 * 4 * 5 * 6.8 *
379+ ************************************************
380+
362381 """
363382 import ROOT
364383 if tree is not None :
@@ -395,5 +414,36 @@ def array2root(arr, filename, treename='tree', mode='update'):
395414 --------
396415 array2tree
397416
417+ Examples
418+ --------
419+
420+ >>> from root_numpy import array2root, root2array
421+ >>> import numpy as np
422+ >>>
423+ >>> a = np.array([(1, 2.5, 3.4),
424+ ... (4, 5, 6.8)],
425+ ... dtype=[('a', np.int32),
426+ ... ('b', np.float32),
427+ ... ('c', np.float64)])
428+ >>> array2root(a, 'test.root', mode='recreate')
429+ >>> root2array('test.root')
430+ array([(1, 2.5, 3.4), (4, 5.0, 6.8)],
431+ dtype=[('a', '<i4'), ('b', '<f4'), ('c', '<f8')])
432+ >>>
433+ >>> a = np.array(['', 'a', 'ab', 'abc', 'xyz', ''],
434+ ... dtype=[('string', 'S3')])
435+ >>> array2root(a, 'test.root', mode='recreate')
436+ >>> root2array('test.root')
437+ array([('',), ('a',), ('ab',), ('abc',), ('xyz',), ('',)],
438+ dtype=[('string', 'S3')])
439+ >>>
440+ >>> a = np.array([([1, 2, 3],),
441+ ... ([4, 5, 6],)],
442+ ... dtype=[('array', np.int32, (3,))])
443+ >>> array2root(a, 'test.root', mode='recreate')
444+ >>> root2array('test.root')
445+ array([([1, 2, 3],), ([4, 5, 6],)],
446+ dtype=[('array', '<i4', (3,))])
447+
398448 """
399449 _librootnumpy .array2root (arr , filename , treename , mode )
0 commit comments