Stacking one-dimensional arrays is a common and powerful operation when combining multiple 1D sequences (e.g., time series channels, sensor readings, feature vectors) into higher-dimensional structures — either horizontally (hstack) to add columns/features or vertically (vstack) to add rows/samples. In NumPy, np.hstack() and np.vstack() are convenience wrappers around concatenate, while Dask offers da.hstack() and da.vstack() with lazy, parallel execution. In 2026, stacking 1D arrays remains essential for data preparation — merging multi-sensor time series, building batch inputs for ML models, aligning features across samples, or creating multi-variate datasets — with Dask enabling scalable stacking of large/out-of-core sequences and xarray providing labeled stacking with dimension management.
Here’s a complete, practical guide to stacking one-dimensional arrays in Python: NumPy hstack/vstack, Dask equivalents, axis behavior, real-world patterns (time series channels, ML batches, sensor fusion), and modern best practices with chunk alignment, memory efficiency, type hints, and Polars/xarray equivalents.
NumPy stacking 1D arrays — hstack joins horizontally (adds columns), vstack vertically (adds rows).
import numpy as np
ts1 = np.array([1.0, 2.0, 3.0, 4.0]) # sensor 1
ts2 = np.array([5.0, 6.0, 7.0, 8.0]) # sensor 2
ts3 = np.array([9.0, 10.0, 11.0, 12.0]) # sensor 3
# Horizontal stack: combine as columns (time × features)
h_stacked = np.hstack([ts1, ts2, ts3]) # shape (12,)
print(h_stacked) # [ 1. 2. 3. 4. 5. 6. 7. 8. 9. 10. 11. 12.]
# To get (time × features), reshape or use column_stack
features = np.column_stack([ts1, ts2, ts3]) # (4, 3)
print(features.shape) # (4, 3)
# Vertical stack: add as new rows/samples (samples × time)
v_stacked = np.vstack([ts1, ts2, ts3]) # shape (3, 4)
print(v_stacked.shape) # (3, 4)
Dask stacking 1D arrays — lazy, parallel, requires compatible chunks.
import dask.array as da
d_ts1 = da.from_array(ts1, chunks=2)
d_ts2 = da.from_array(ts2, chunks=2)
d_ts3 = da.from_array(ts3, chunks=2)
# Lazy hstack ? concatenate along axis=0 (length)
d_h = da.hstack([d_ts1, d_ts2, d_ts3])
print(d_h.compute().shape) # (12,)
# Lazy vstack ? concatenate along new axis=0
d_v = da.vstack([d_ts1, d_ts2, d_ts3])
print(d_v.compute().shape) # (3, 4)
Real-world pattern: stacking multi-sensor time series or ML feature vectors.
# Multiple sensors: each 1000 time steps
sensor_data = [np.random.rand(1000) for _ in range(5)] # 5 sensors
# Stack as (time × sensors)
multi_ts = np.column_stack(sensor_data) # (1000, 5)
print(multi_ts.shape) # (1000, 5)
# Dask version for large series
d_sensors = [da.from_array(s, chunks=200) for s in sensor_data]
d_multi = da.concatenate(d_sensors, axis=1) # or da.stack(..., axis=1)
print(d_multi.compute().shape) # (1000, 5)
Best practices for stacking 1D arrays. Prefer np.column_stack() — for 1D ? 2D (time × features). Modern tip: use Polars .hstack() or xarray xr.concat(..., dim='feature') — labeled stacking avoids manual axis management. Ensure equal lengths — all arrays must match in non-stacked dimensions. Check chunk alignment in Dask — rechunk before stacking if needed. Use axis=0 for samples, axis=1 for features/channels. Add type hints — def stack_1d(arrs: list[np.ndarray[np.float64, (None,)]]) -> np.ndarray[np.float64, (None, None)]. Monitor memory — stacking adds dimension (no copy if views). Use np.ascontiguousarray — ensure C-order after stacking. Use xarray — xr.concat([da1, da2], dim='time') — preserves labels. Use Dask — da.stack()/da.concatenate() for lazy large arrays. Test stacking — assert stacked[:, 0].equals(original1). Use np.vstack/np.hstack — convenience for 1D/2D. Use da.rechunk() — align chunks before stacking. Profile with timeit — compare stack vs manual loops.
Stacking one-dimensional arrays combines sequences horizontally (features) or vertically (samples) — NumPy hstack/vstack/column_stack, Dask lazy equivalents. In 2026, use column_stack for time × features, Polars/xarray for labeled stacking, Dask for scale, and verify shapes/chunks. Master stacking 1D arrays, and you’ll assemble multi-variate time series, sensor data, or feature matrices efficiently and correctly.
Next time you need to combine 1D series — stack them right. It’s Python’s cleanest way to say: “Merge these sequences — into a multi-dimensional array with proper order.”