labscript.utils.fastflatten
- fastflatten(inarray, dtype)[source]
A faster way of flattening our arrays than pylab.flatten.
pylab.flatten returns a generator which takes a lot of time and memory to convert into a numpy array via array(list(generator)). The problem is that generators don’t know how many values they’ll return until they’re done. This algorithm produces a numpy array directly by first calculating what the length will be. It is several orders of magnitude faster. Note that we can’t use numpy.ndarray.flatten here since our inarray is really a list of 1D arrays of varying length and/or single values, not a N-dimenional block of homogeneous data like a numpy array.
- Parameters:
inarray (list) – List of 1-D arrays to flatten.
dtype (data-type) – Type of the data in the arrays.
- Returns:
Flattened array.
- Return type: