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)
| 1464 | |
| 1465 | |
| 1466 | def concatenate(seq, axis=0, allow_unknown_chunksizes=False): |
| 1467 | """ |
| 1468 | Concatenate arrays along an existing axis |
| 1469 | |
| 1470 | Given a sequence of dask Arrays form a new dask Array by stacking them |
| 1471 | along an existing dimension (axis=0 by default) |
| 1472 | |
| 1473 | Parameters |
| 1474 | ---------- |
| 1475 | seq: list of dask.arrays |
| 1476 | axis: int |
| 1477 | Dimension along which to align all of the arrays. If axis is None, |
| 1478 | arrays are flattened before use. |
| 1479 | allow_unknown_chunksizes: bool |
| 1480 | Allow unknown chunksizes, such as come from converting from dask |
| 1481 | dataframes. Dask.array is unable to verify that chunks line up. If |
| 1482 | data comes from differently aligned sources then this can cause |
| 1483 | unexpected results. |
| 1484 | |
| 1485 | Examples |
| 1486 | -------- |
| 1487 | |
| 1488 | Create slices |
| 1489 | |
| 1490 | >>> import dask.array as da |
| 1491 | >>> import numpy as np |
| 1492 | |
| 1493 | >>> data = [da.from_array(np.ones((4, 4)), chunks=(2, 2)) |
| 1494 | ... for i in range(3)] |
| 1495 | |
| 1496 | >>> x = da.concatenate(data, axis=0) |
| 1497 | >>> x.shape |
| 1498 | (12, 4) |
| 1499 | |
| 1500 | >>> da.concatenate(data, axis=1).shape |
| 1501 | (4, 12) |
| 1502 | |
| 1503 | Result is a new dask Array |
| 1504 | |
| 1505 | See Also |
| 1506 | -------- |
| 1507 | stack |
| 1508 | """ |
| 1509 | from dask.array import wrap |
| 1510 | |
| 1511 | seq = [asarray(a, allow_unknown_chunksizes=allow_unknown_chunksizes) for a in seq] |
| 1512 | |
| 1513 | if not seq: |
| 1514 | raise ValueError("Need array(s) to concatenate") |
| 1515 | |
| 1516 | if axis is None: |
| 1517 | seq = [a.flatten() for a in seq] |
| 1518 | axis = 0 |
| 1519 | |
| 1520 | seq_metas = [meta_from_array(s) for s in seq] |
| 1521 | _concatenate = concatenate_lookup.dispatch( |
| 1522 | type(max(seq_metas, key=lambda x: getattr(x, "__array_priority__", 0))) |
| 1523 | ) |
no test coverage detected
searching dependent graphs…