Concatenate arrays along an existing axis Given a sequence of dask Arrays form a new dask Array by stacking them along an existing dimension (axis=0 by default) Parameters ---------- seq: list of dask.arrays axis: int Dimension along which to align all of the a
(seq, axis=0, allow_unknown_chunksizes=False)
| 4414 | |
| 4415 | |
| 4416 | def concatenate(seq, axis=0, allow_unknown_chunksizes=False): |
| 4417 | """ |
| 4418 | Concatenate arrays along an existing axis |
| 4419 | |
| 4420 | Given a sequence of dask Arrays form a new dask Array by stacking them |
| 4421 | along an existing dimension (axis=0 by default) |
| 4422 | |
| 4423 | Parameters |
| 4424 | ---------- |
| 4425 | seq: list of dask.arrays |
| 4426 | axis: int |
| 4427 | Dimension along which to align all of the arrays. If axis is None, |
| 4428 | arrays are flattened before use. |
| 4429 | allow_unknown_chunksizes: bool |
| 4430 | Allow unknown chunksizes, such as come from converting from dask |
| 4431 | dataframes. Dask.array is unable to verify that chunks line up. If |
| 4432 | data comes from differently aligned sources then this can cause |
| 4433 | unexpected results. |
| 4434 | |
| 4435 | Examples |
| 4436 | -------- |
| 4437 | |
| 4438 | Create slices |
| 4439 | |
| 4440 | >>> import dask.array as da |
| 4441 | >>> import numpy as np |
| 4442 | |
| 4443 | >>> data = [da.from_array(np.ones((4, 4)), chunks=(2, 2)) |
| 4444 | ... for i in range(3)] |
| 4445 | |
| 4446 | >>> x = da.concatenate(data, axis=0) |
| 4447 | >>> x.shape |
| 4448 | (12, 4) |
| 4449 | |
| 4450 | >>> da.concatenate(data, axis=1).shape |
| 4451 | (4, 12) |
| 4452 | |
| 4453 | Result is a new dask Array |
| 4454 | |
| 4455 | See Also |
| 4456 | -------- |
| 4457 | stack |
| 4458 | """ |
| 4459 | from dask.array import wrap |
| 4460 | |
| 4461 | seq = [asarray(a, allow_unknown_chunksizes=allow_unknown_chunksizes) for a in seq] |
| 4462 | |
| 4463 | if not seq: |
| 4464 | raise ValueError("Need array(s) to concatenate") |
| 4465 | |
| 4466 | if axis is None: |
| 4467 | seq = [a.flatten() for a in seq] |
| 4468 | axis = 0 |
| 4469 | |
| 4470 | seq_metas = [meta_from_array(s) for s in seq] |
| 4471 | _concatenate = concatenate_lookup.dispatch( |
| 4472 | type(max(seq_metas, key=lambda x: getattr(x, "__array_priority__", 0))) |
| 4473 | ) |