root_numpy.stretch(arr, fields=None, return_indices=False)

Stretch an array.

Stretch an array by hstack()-ing multiple array fields while preserving column names and record array structure. If a scalar field is specified, it will be stretched along with array fields.


arr : NumPy structured or record array

The array to be stretched.

fields : list of strings or string, optional (default=None)

A list of column names or a single column name to stretch. If fields is a string, then the output array is a one-dimensional unstructured array containing only the stretched elements of that field. If None, then stretch all fields.

return_indices : bool, optional (default=False)

If True, the array index of each stretched array entry will be returned in addition to the stretched array. This changes the return type of this function to a tuple consisting of a structured array and a numpy int64 array.


ret : A NumPy structured array

The stretched array.


>>> import numpy as np
>>> from root_numpy import stretch
>>> arr = np.empty(2, dtype=[('scalar',, ('array', 'O')])
>>> arr[0] = (0, np.array([1, 2, 3], dtype=np.float))
>>> arr[1] = (1, np.array([4, 5, 6], dtype=np.float))
>>> stretch(arr, ['scalar', 'array'])
array([(0, 1.0), (0, 2.0), (0, 3.0), (1, 4.0), (1, 5.0), (1, 6.0)],
    dtype=[('scalar', '<i8'), ('array', '<f8')])