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)
| 4616 | |
| 4617 | |
| 4618 | def concatenate(seq, axis=0, allow_unknown_chunksizes=False): |
| 4619 | """ |
| 4620 | Concatenate arrays along an existing axis |
| 4621 | |
| 4622 | Given a sequence of dask Arrays form a new dask Array by stacking them |
| 4623 | along an existing dimension (axis=0 by default) |
| 4624 | |
| 4625 | Parameters |
| 4626 | ---------- |
| 4627 | seq: list of dask.arrays |
| 4628 | axis: int |
| 4629 | Dimension along which to align all of the arrays. If axis is None, |
| 4630 | arrays are flattened before use. |
| 4631 | allow_unknown_chunksizes: bool |
| 4632 | Allow unknown chunksizes, such as come from converting from dask |
| 4633 | dataframes. Dask.array is unable to verify that chunks line up. If |
| 4634 | data comes from differently aligned sources then this can cause |
| 4635 | unexpected results. |
| 4636 | |
| 4637 | Examples |
| 4638 | -------- |
| 4639 | |
| 4640 | Create slices |
| 4641 | |
| 4642 | >>> import dask.array as da |
| 4643 | >>> import numpy as np |
| 4644 | |
| 4645 | >>> data = [da.from_array(np.ones((4, 4)), chunks=(2, 2)) |
| 4646 | ... for i in range(3)] |
| 4647 | |
| 4648 | >>> x = da.concatenate(data, axis=0) |
| 4649 | >>> x.shape |
| 4650 | (12, 4) |
| 4651 | |
| 4652 | >>> da.concatenate(data, axis=1).shape |
| 4653 | (4, 12) |
| 4654 | |
| 4655 | Result is a new dask Array |
| 4656 | |
| 4657 | See Also |
| 4658 | -------- |
| 4659 | stack |
| 4660 | """ |
| 4661 | from dask.array import wrap |
| 4662 | |
| 4663 | seq = [asarray(a, allow_unknown_chunksizes=allow_unknown_chunksizes) for a in seq] |
| 4664 | |
| 4665 | if not seq: |
| 4666 | raise ValueError("Need array(s) to concatenate") |
| 4667 | |
| 4668 | if axis is None: |
| 4669 | seq = [a.flatten() for a in seq] |
| 4670 | axis = 0 |
| 4671 | |
| 4672 | seq_metas = [meta_from_array(s) for s in seq] |
| 4673 | _concatenate = concatenate_lookup.dispatch( |
| 4674 | type(max(seq_metas, key=lambda x: getattr(x, "__array_priority__", 0))) |
| 4675 | ) |
searching dependent graphs…