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)
| 777 | |
| 778 | @array_function_dispatch(_block_dispatcher) |
| 779 | def block(arrays): |
| 780 | """ |
| 781 | Assemble an nd-array from nested lists of blocks. |
| 782 | |
| 783 | Blocks in the innermost lists are concatenated (see `concatenate`) along |
| 784 | the last dimension (-1), then these are concatenated along the |
| 785 | second-last dimension (-2), and so on until the outermost list is reached. |
| 786 | |
| 787 | Blocks can be of any dimension, but will not be broadcasted using |
| 788 | the normal rules. Instead, leading axes of size 1 are inserted, |
| 789 | to make ``block.ndim`` the same for all blocks. This is primarily useful |
| 790 | for working with scalars, and means that code like ``np.block([v, 1])`` |
| 791 | is valid, where ``v.ndim == 1``. |
| 792 | |
| 793 | When the nested list is two levels deep, this allows block matrices to be |
| 794 | constructed from their components. |
| 795 | |
| 796 | Parameters |
| 797 | ---------- |
| 798 | arrays : nested list of array_like or scalars (but not tuples) |
| 799 | If passed a single ndarray or scalar (a nested list of depth 0), this |
| 800 | is returned unmodified (and not copied). |
| 801 | |
| 802 | Elements shapes must match along the appropriate axes (without |
| 803 | broadcasting), but leading 1s will be prepended to the shape as |
| 804 | necessary to make the dimensions match. |
| 805 | |
| 806 | Returns |
| 807 | ------- |
| 808 | block_array : ndarray |
| 809 | The array assembled from the given blocks. |
| 810 | |
| 811 | The dimensionality of the output is equal to the greatest of: |
| 812 | |
| 813 | * the dimensionality of all the inputs |
| 814 | * the depth to which the input list is nested |
| 815 | |
| 816 | Raises |
| 817 | ------ |
| 818 | ValueError |
| 819 | * If list depths are mismatched - for instance, ``[[a, b], c]`` is |
| 820 | illegal, and should be spelt ``[[a, b], [c]]`` |
| 821 | * If lists are empty - for instance, ``[[a, b], []]`` |
| 822 | |
| 823 | See Also |
| 824 | -------- |
| 825 | concatenate : Join a sequence of arrays along an existing axis. |
| 826 | stack : Join a sequence of arrays along a new axis. |
| 827 | vstack : Stack arrays in sequence vertically (row wise). |
| 828 | hstack : Stack arrays in sequence horizontally (column wise). |
| 829 | dstack : Stack arrays in sequence depth wise (along third axis). |
| 830 | column_stack : Stack 1-D arrays as columns into a 2-D array. |
| 831 | vsplit : Split an array into multiple sub-arrays vertically (row-wise). |
| 832 | unstack : Split an array into a tuple of sub-arrays along an axis. |
| 833 | |
| 834 | Notes |
| 835 | ----- |
| 836 | When called with only scalars, ``np.block`` is equivalent to an ndarray |
searching dependent graphs…