Assemble an nd-array from nested lists of blocks. Blocks in the innermost lists are concatenated (see `concatenate`) along the last dimension (-1), then these are concatenated along the second-last dimension (-2), and so on until the outermost list is reached. Blocks can be of
(arrays)
| 702 | |
| 703 | @array_function_dispatch(_block_dispatcher) |
| 704 | def block(arrays): |
| 705 | """ |
| 706 | Assemble an nd-array from nested lists of blocks. |
| 707 | |
| 708 | Blocks in the innermost lists are concatenated (see `concatenate`) along |
| 709 | the last dimension (-1), then these are concatenated along the |
| 710 | second-last dimension (-2), and so on until the outermost list is reached. |
| 711 | |
| 712 | Blocks can be of any dimension, but will not be broadcasted using the normal |
| 713 | rules. Instead, leading axes of size 1 are inserted, to make ``block.ndim`` |
| 714 | the same for all blocks. This is primarily useful for working with scalars, |
| 715 | and means that code like ``np.block([v, 1])`` is valid, where |
| 716 | ``v.ndim == 1``. |
| 717 | |
| 718 | When the nested list is two levels deep, this allows block matrices to be |
| 719 | constructed from their components. |
| 720 | |
| 721 | .. versionadded:: 1.13.0 |
| 722 | |
| 723 | Parameters |
| 724 | ---------- |
| 725 | arrays : nested list of array_like or scalars (but not tuples) |
| 726 | If passed a single ndarray or scalar (a nested list of depth 0), this |
| 727 | is returned unmodified (and not copied). |
| 728 | |
| 729 | Elements shapes must match along the appropriate axes (without |
| 730 | broadcasting), but leading 1s will be prepended to the shape as |
| 731 | necessary to make the dimensions match. |
| 732 | |
| 733 | Returns |
| 734 | ------- |
| 735 | block_array : ndarray |
| 736 | The array assembled from the given blocks. |
| 737 | |
| 738 | The dimensionality of the output is equal to the greatest of: |
| 739 | * the dimensionality of all the inputs |
| 740 | * the depth to which the input list is nested |
| 741 | |
| 742 | Raises |
| 743 | ------ |
| 744 | ValueError |
| 745 | * If list depths are mismatched - for instance, ``[[a, b], c]`` is |
| 746 | illegal, and should be spelt ``[[a, b], [c]]`` |
| 747 | * If lists are empty - for instance, ``[[a, b], []]`` |
| 748 | |
| 749 | See Also |
| 750 | -------- |
| 751 | concatenate : Join a sequence of arrays along an existing axis. |
| 752 | stack : Join a sequence of arrays along a new axis. |
| 753 | vstack : Stack arrays in sequence vertically (row wise). |
| 754 | hstack : Stack arrays in sequence horizontally (column wise). |
| 755 | dstack : Stack arrays in sequence depth wise (along third axis). |
| 756 | column_stack : Stack 1-D arrays as columns into a 2-D array. |
| 757 | vsplit : Split an array into multiple sub-arrays vertically (row-wise). |
| 758 | |
| 759 | Notes |
| 760 | ----- |
| 761 |