brainmass.process_sequence#
- brainmass.process_sequence(data, mode='stack')[source]#
Stack a sequence of data items along a new dimension.
This is the inverse operation of slice_data - while slice_data reduces a dimension via aggregation, stack_data creates a new dimension by stacking multiple items together.
- Returns:
mode=’stack’: Array/dict/tuple/list with new dimension at dim
mode=’last’/’first’: Single item (same as data[-1] or data[0])
mode=’avg’/’mean’/’max’/’min’: Aggregated tensor/dict/tuple/list
mode=callable: Result of applying callable to stacked data
For dicts/tuples/lists, aggregation is applied recursively to each element.
- Return type:
Array|ndarray|bool|number|bool|int|float|complex|Quantity|Tuple|List|Dict|Sequence- Raises:
ValueError – If data is empty (cannot infer structure/type) or if mode is an unknown string.
TypeError – If sequence contains mixed or incompatible types, or if mode is not a string or callable.
- Parameters:
Notes
All elements in data must have the same type and structure
NumPy arrays are automatically converted to float32 tensors
Dictionary keys must match across all elements
Tuple/list lengths must match across all elements
Recursive: handles nested structures (e.g., dict of tuples)