/ lib / numpy / core / shape_base.pyc
shape_base.pyc
  1  o

  2  [��c�z�@s�gd�ZddlZddlZddlZddlZddlmZddlmZddl	m
  3  Z
  4  mZmZddlm
Zejejdd	�Zd
  5  d�Zee�dd
��Zdd�Zee�dd��Zdd�Zee�dd��Zd>dd�Zddd�dd�Zee�ddd�dd��Zee�ddd�dd ��Zd?ddd�d!d"�Zee�d@ddd�d#d$��Zeejd%ej�Zeej d%ej �Z!eej"d%ej"�Z#d&d'�Z$gfd(d)�Z%d*d+�Z&d,d-�Z'd.d/�Z(dAd0d1�Z)dAd2d3�Z*d4d5�Z+ee+�d6d7��Z,d8d9�Z-d:d;�Z.d<d=�Z/dS)B)�
  6  atleast_1d�
  7  atleast_2d�
  8  atleast_3d�block�hstack�stack�vstack�N�)�numeric)�	overrides)�array�
  9  asanyarray�normalize_axis_index)�fromnumeric�numpy)�modulecG�|S�N���arysrr��C:\Users\Jacks.GUTTSPC\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\numpy\core\shape_base.py�_atleast_1d_dispatcher�rcGsRg}|D]}t|�}|jdkr|�d�}n|}|�|�qt|�dkr'|dS|S)a
 10      Convert inputs to arrays with at least one dimension.
 11  
 12      Scalar inputs are converted to 1-dimensional arrays, whilst
 13      higher-dimensional inputs are preserved.
 14  
 15      Parameters
 16      ----------
 17      arys1, arys2, ... : array_like
 18          One or more input arrays.
 19  
 20      Returns
 21      -------
 22      ret : ndarray
 23          An array, or list of arrays, each with ``a.ndim >= 1``.
 24          Copies are made only if necessary.
 25  
 26      See Also
 27      --------
 28      atleast_2d, atleast_3d
 29  
 30      Examples
 31      --------
 32      >>> np.atleast_1d(1.0)
 33      array([1.])
 34  
 35      >>> x = np.arange(9.0).reshape(3,3)
 36      >>> np.atleast_1d(x)
 37      array([[0., 1., 2.],
 38             [3., 4., 5.],
 39             [6., 7., 8.]])
 40      >>> np.atleast_1d(x) is x
 41      True
 42  
 43      >>> np.atleast_1d(1, [3, 4])
 44      [array([1]), array([3, 4])]
 45  
 46      rr	)r
�ndim�reshape�append�len�r�res�ary�resultrrrrs(
 47  rcGrrrrrrr�_atleast_2d_dispatcherMrr"cGsrg}|D](}t|�}|jdkr|�dd�}n|jdkr%|tjdd�f}n|}|�|�qt|�dkr7|dS|S)a\
 48      View inputs as arrays with at least two dimensions.
 49  
 50      Parameters
 51      ----------
 52      arys1, arys2, ... : array_like
 53          One or more array-like sequences.  Non-array inputs are converted
 54          to arrays.  Arrays that already have two or more dimensions are
 55          preserved.
 56  
 57      Returns
 58      -------
 59      res, res2, ... : ndarray
 60          An array, or list of arrays, each with ``a.ndim >= 2``.
 61          Copies are avoided where possible, and views with two or more
 62          dimensions are returned.
 63  
 64      See Also
 65      --------
 66      atleast_1d, atleast_3d
 67  
 68      Examples
 69      --------
 70      >>> np.atleast_2d(3.0)
 71      array([[3.]])
 72  
 73      >>> x = np.arange(3.0)
 74      >>> np.atleast_2d(x)
 75      array([[0., 1., 2.]])
 76      >>> np.atleast_2d(x).base is x
 77      True
 78  
 79      >>> np.atleast_2d(1, [1, 2], [[1, 2]])
 80      [array([[1]]), array([[1, 2]]), array([[1, 2]])]
 81  
 82      rr	N�r
rr�_nx�newaxisrrrrrrrQs&
 83  
 84  rcGrrrrrrr�_atleast_3d_dispatcher�rr&cGs�g}|D]=}t|�}|jdkr|�ddd�}n%|jdkr(|tjdd�tjf}n|jdkr:|dd�dd�tjf}n|}|�|�qt|�dkrL|dS|S)a
 85      View inputs as arrays with at least three dimensions.
 86  
 87      Parameters
 88      ----------
 89      arys1, arys2, ... : array_like
 90          One or more array-like sequences.  Non-array inputs are converted to
 91          arrays.  Arrays that already have three or more dimensions are
 92          preserved.
 93  
 94      Returns
 95      -------
 96      res1, res2, ... : ndarray
 97          An array, or list of arrays, each with ``a.ndim >= 3``.  Copies are
 98          avoided where possible, and views with three or more dimensions are
 99          returned.  For example, a 1-D array of shape ``(N,)`` becomes a view
100          of shape ``(1, N, 1)``, and a 2-D array of shape ``(M, N)`` becomes a
101          view of shape ``(M, N, 1)``.
102  
103      See Also
104      --------
105      atleast_1d, atleast_2d
106  
107      Examples
108      --------
109      >>> np.atleast_3d(3.0)
110      array([[[3.]]])
111  
112      >>> x = np.arange(3.0)
113      >>> np.atleast_3d(x).shape
114      (1, 3, 1)
115  
116      >>> x = np.arange(12.0).reshape(4,3)
117      >>> np.atleast_3d(x).shape
118      (4, 3, 1)
119      >>> np.atleast_3d(x).base is x.base  # x is a reshape, so not base itself
120      True
121  
122      >>> for arr in np.atleast_3d([1, 2], [[1, 2]], [[[1, 2]]]):
123      ...     print(arr, arr.shape) # doctest: +SKIP
124      ...
125      [[[1]
126        [2]]] (1, 2, 1)
127      [[[1]
128        [2]]] (1, 2, 1)
129      [[[1 2]]] (1, 1, 2)
130  
131      rr	N�r#rrrrr�s2
132  
133  
134  r�cCs,t|d�st|d�rtjdt|d�dS|S)N�__getitem__�__iter__z�arrays to stack must be passed as a "sequence" type such as list or tuple. Support for non-sequence iterables such as generators is deprecated as of NumPy 1.16 and will raise an error in the future.��
135  stacklevelr)�hasattr�warnings�warn�
FutureWarning)�arraysr,rrr�_arrays_for_stack_dispatcher�s�r2��dtype�castingcCst|�Sr)r2)�tupr4r5rrr�_vhstack_dispatcher�sr7�	same_kindcCs<tjs	t|dd�t|�}t|t�s|g}tj|d||d�S)a>
136      Stack arrays in sequence vertically (row wise).
137  
138      This is equivalent to concatenation along the first axis after 1-D arrays
139      of shape `(N,)` have been reshaped to `(1,N)`. Rebuilds arrays divided by
140      `vsplit`.
141  
142      This function makes most sense for arrays with up to 3 dimensions. For
143      instance, for pixel-data with a height (first axis), width (second axis),
144      and r/g/b channels (third axis). The functions `concatenate`, `stack` and
145      `block` provide more general stacking and concatenation operations.
146  
147      ``np.row_stack`` is an alias for `vstack`. They are the same function.
148  
149      Parameters
150      ----------
151      tup : sequence of ndarrays
152          The arrays must have the same shape along all but the first axis.
153          1-D arrays must have the same length.
154  
155      dtype : str or dtype
156          If provided, the destination array will have this dtype. Cannot be
157          provided together with `out`.
158  
159      .. versionadded:: 1.24
160  
161      casting : {'no', 'equiv', 'safe', 'same_kind', 'unsafe'}, optional
162          Controls what kind of data casting may occur. Defaults to 'same_kind'.
163  
164      .. versionadded:: 1.24
165  
166      Returns
167      -------
168      stacked : ndarray
169          The array formed by stacking the given arrays, will be at least 2-D.
170  
171      See Also
172      --------
173      concatenate : Join a sequence of arrays along an existing axis.
174      stack : Join a sequence of arrays along a new axis.
175      block : Assemble an nd-array from nested lists of blocks.
176      hstack : Stack arrays in sequence horizontally (column wise).
177      dstack : Stack arrays in sequence depth wise (along third axis).
178      column_stack : Stack 1-D arrays as columns into a 2-D array.
179      vsplit : Split an array into multiple sub-arrays vertically (row-wise).
180  
181      Examples
182      --------
183      >>> a = np.array([1, 2, 3])
184      >>> b = np.array([4, 5, 6])
185      >>> np.vstack((a,b))
186      array([[1, 2, 3],
187             [4, 5, 6]])
188  
189      >>> a = np.array([[1], [2], [3]])
190      >>> b = np.array([[4], [5], [6]])
191      >>> np.vstack((a,b))
192      array([[1],
193             [2],
194             [3],
195             [4],
196             [5],
197             [6]])
198  
199      r'r+rr3)r�ARRAY_FUNCTION_ENABLEDr2r�
200  isinstance�listr$�concatenate�r6r4r5�arrsrrrr�sC
201  rcCs`tjs	t|dd�t|�}t|t�s|g}|r'|djdkr'tj|d||d�Stj|d||d�S)a�
202      Stack arrays in sequence horizontally (column wise).
203  
204      This is equivalent to concatenation along the second axis, except for 1-D
205      arrays where it concatenates along the first axis. Rebuilds arrays divided
206      by `hsplit`.
207  
208      This function makes most sense for arrays with up to 3 dimensions. For
209      instance, for pixel-data with a height (first axis), width (second axis),
210      and r/g/b channels (third axis). The functions `concatenate`, `stack` and
211      `block` provide more general stacking and concatenation operations.
212  
213      Parameters
214      ----------
215      tup : sequence of ndarrays
216          The arrays must have the same shape along all but the second axis,
217          except 1-D arrays which can be any length.
218  
219      dtype : str or dtype
220          If provided, the destination array will have this dtype. Cannot be
221          provided together with `out`.
222  
223      .. versionadded:: 1.24
224  
225      casting : {'no', 'equiv', 'safe', 'same_kind', 'unsafe'}, optional
226          Controls what kind of data casting may occur. Defaults to 'same_kind'.
227  
228      .. versionadded:: 1.24
229  
230      Returns
231      -------
232      stacked : ndarray
233          The array formed by stacking the given arrays.
234  
235      See Also
236      --------
237      concatenate : Join a sequence of arrays along an existing axis.
238      stack : Join a sequence of arrays along a new axis.
239      block : Assemble an nd-array from nested lists of blocks.
240      vstack : Stack arrays in sequence vertically (row wise).
241      dstack : Stack arrays in sequence depth wise (along third axis).
242      column_stack : Stack 1-D arrays as columns into a 2-D array.
243      hsplit : Split an array into multiple sub-arrays horizontally (column-wise).
244  
245      Examples
246      --------
247      >>> a = np.array((1,2,3))
248      >>> b = np.array((4,5,6))
249      >>> np.hstack((a,b))
250      array([1, 2, 3, 4, 5, 6])
251      >>> a = np.array([[1],[2],[3]])
252      >>> b = np.array([[4],[5],[6]])
253      >>> np.hstack((a,b))
254      array([[1, 4],
255             [2, 5],
256             [3, 6]])
257  
258      r'r+rr	r3)	rr9r2rr:r;rr$r<r=rrrr+s<
259  rcCs*t|dd�}|durt|�}|�|�|S)N�r+)r2r;r)r1�axis�outr4r5rrr�_stack_dispatcherus
260  
261  rBcs�tjs	t|dd�dd�|D�}|std��dd�|D�}t|�dkr'td	��|d
262  jd}t||�}td�f|tj	f��fdd�|D�}tj
263  |||||d
�S)aw
264      Join a sequence of arrays along a new axis.
265  
266      The ``axis`` parameter specifies the index of the new axis in the
267      dimensions of the result. For example, if ``axis=0`` it will be the first
268      dimension and if ``axis=-1`` it will be the last dimension.
269  
270      .. versionadded:: 1.10.0
271  
272      Parameters
273      ----------
274      arrays : sequence of array_like
275          Each array must have the same shape.
276  
277      axis : int, optional
278          The axis in the result array along which the input arrays are stacked.
279  
280      out : ndarray, optional
281          If provided, the destination to place the result. The shape must be
282          correct, matching that of what stack would have returned if no
283          out argument were specified.
284  
285      dtype : str or dtype
286          If provided, the destination array will have this dtype. Cannot be
287          provided together with `out`.
288  
289          .. versionadded:: 1.24
290  
291      casting : {'no', 'equiv', 'safe', 'same_kind', 'unsafe'}, optional
292          Controls what kind of data casting may occur. Defaults to 'same_kind'.
293  
294          .. versionadded:: 1.24
295  
296  
297      Returns
298      -------
299      stacked : ndarray
300          The stacked array has one more dimension than the input arrays.
301  
302      See Also
303      --------
304      concatenate : Join a sequence of arrays along an existing axis.
305      block : Assemble an nd-array from nested lists of blocks.
306      split : Split array into a list of multiple sub-arrays of equal size.
307  
308      Examples
309      --------
310      >>> arrays = [np.random.randn(3, 4) for _ in range(10)]
311      >>> np.stack(arrays, axis=0).shape
312      (10, 3, 4)
313  
314      >>> np.stack(arrays, axis=1).shape
315      (3, 10, 4)
316  
317      >>> np.stack(arrays, axis=2).shape
318      (3, 4, 10)
319  
320      >>> a = np.array([1, 2, 3])
321      >>> b = np.array([4, 5, 6])
322      >>> np.stack((a, b))
323      array([[1, 2, 3],
324             [4, 5, 6]])
325  
326      >>> np.stack((a, b), axis=-1)
327      array([[1, 4],
328             [2, 5],
329             [3, 6]])
330  
331      r'r+cSsg|]}t|��qSr)r
��.0�arrrrr�
332  <listcomp>��zstack.<locals>.<listcomp>z need at least one array to stackcSsh|]}|j�qSr)�shaperCrrr�	<setcomp>��zstack.<locals>.<setcomp>r	z)all input arrays must have the same shaperNc�g|]}|��qSrrrC��slrrrF�rG)r@rAr4r5)rr9r2�
333  ValueErrorrrr�slicer$r%r<)r1r@rAr4r5�shapes�result_ndimZexpanded_arraysrrLrrsG
334  
335  �r�__wrapped__cCsd�dd�|D��}d|S)zM
336      Convert a list of indices ``[0, 1, 2]`` into ``"arrays[0][1][2]"``.
337      �css"�|]}|durd�|�VqdS)Nz[{}])�format)rD�irrr�	<genexpr>�s� z&_block_format_index.<locals>.<genexpr>r1)�join)�indexZidx_strrrr�_block_format_index�srYc	st|�turtd�t�����t|�turct|�dkrc�fdd�t|�D�}t|�\}}}|D].\}}}||7}||kr>|}t|�t|�krUt	d�t|�t|�t|����|ddur]|}q/|||fSt|�turwt|�dkrw�dgddfSt
338  |�}�t|�|fS)a�
339      Recursive function checking that the depths of nested lists in `arrays`
340      all match. Mismatch raises a ValueError as described in the block
341      docstring below.
342  
343      The entire index (rather than just the depth) needs to be calculated
344      for each innermost list, in case an error needs to be raised, so that
345      the index of the offending list can be printed as part of the error.
346  
347      Parameters
348      ----------
349      arrays : nested list of arrays
350          The arrays to check
351      parent_index : list of int
352          The full index of `arrays` within the nested lists passed to
353          `_block_check_depths_match` at the top of the recursion.
354  
355      Returns
356      -------
357      first_index : list of int
358          The full index of an element from the bottom of the nesting in
359          `arrays`. If any element at the bottom is an empty list, this will
360          refer to it, and the last index along the empty axis will be None.
361      max_arr_ndim : int
362          The maximum of the ndims of the arrays nested in `arrays`.
363      final_size: int
364          The number of elements in the final array. This is used the motivate
365          the choice of algorithm used using benchmarking wisdom.
366  
367      z{} is a tuple. Only lists can be used to arrange blocks, and np.block does not allow implicit conversion from tuple to ndarray.rc3s$�|]
\}}t|�|g�VqdSr)�_block_check_depths_match)rDrUrE��parent_indexrrrVs��z,_block_check_depths_match.<locals>.<genexpr>zcList depths are mismatched. First element was at depth {}, but there is an element at depth {} ({})�����N)�type�tuple�	TypeErrorrTrYr;r�	enumerate�nextrN�_size�_ndim)	r1r\Z
368  idxs_ndimsZfirst_indexZmax_arr_ndim�
369  final_sizerXr�sizerr[rrZ�sB��
370  ���	�
371  rZcCst||ddd�S)NFT)�ndmin�copy�subok)r)�arrrr�_atleast_nd8srkcCstt�|��Sr)r;�	itertools�
372  accumulate)�valuesrrr�_accumulate>srocs��fdd�|D�}|d}|d���|�dd��t���fdd�|D��r/td������t|�f|�dd�}t|�}d	d�tdg||�D�}||fS)
373  a�Given array shapes, return the resulting shape and slices prefixes.
374  
375      These help in nested concatenation.
376  
377      Returns
378      -------
379      shape: tuple of int
380          This tuple satisfies::
381  
382              shape, _ = _concatenate_shapes([arr.shape for shape in arrs], axis)
383              shape == concatenate(arrs, axis).shape
384  
385      slice_prefixes: tuple of (slice(start, end), )
386          For a list of arrays being concatenated, this returns the slice
387          in the larger array at axis that needs to be sliced into.
388  
389          For example, the following holds::
390  
391              ret = concatenate([a, b, c], axis)
392              _, (sl_a, sl_b, sl_c) = concatenate_slices([a, b, c], axis)
393  
394              ret[(slice(None),) * axis + sl_a] == a
395              ret[(slice(None),) * axis + sl_b] == b
396              ret[(slice(None),) * axis + sl_c] == c
397  
398          These are called slice prefixes since they are used in the recursive
399          blocking algorithm to compute the left-most slices during the
400          recursion. Therefore, they must be prepended to rest of the slice
401          that was computed deeper in the recursion.
402  
403          These are returned as tuples to ensure that they can quickly be added
404          to existing slice tuple without creating a new tuple every time.
405  
406      crKrr�rDrH�r@rrrFfrGz'_concatenate_shapes.<locals>.<listcomp>rNr	c3s4�|]}|d���kp|�dd��kVqdS)Nr	rrp�r@Zfirst_shape_postZfirst_shape_prerrrVms��
407  �z&_concatenate_shapes.<locals>.<genexpr>z/Mismatched array shapes in block along axis {}.cSsg|]
408  \}}t||�f�qSr)rO)rD�start�endrrrrFus�)�anyrNrT�sumro�zip)rPr@Z
shape_at_axisZfirst_shaperHZoffsets_at_axis�slice_prefixesrrrr�_concatenate_shapesBs$$��
409  ��ryc
410  s���kr7t���fdd�|D��\}}}���}t||�\}}dd�t||�D�}t�tj|�}|||fSt|��}	|	jdg|	gfS)a
411      Returns the shape of the final array, along with a list
412      of slices and a list of arrays that can be used for assignment inside the
413      new array
414  
415      Parameters
416      ----------
417      arrays : nested list of arrays
418          The arrays to check
419      max_depth : list of int
420          The number of nested lists
421      result_ndim : int
422          The number of dimensions in thefinal array.
423  
424      Returns
425      -------
426      shape : tuple of int
427          The shape that the final array will take on.
428      slices: list of tuple of slices
429          The slices into the full array required for assignment. These are
430          required to be prepended with ``(Ellipsis, )`` to obtain to correct
431          final index.
432      arrays: list of ndarray
433          The data to assign to each slice of the full array
434  
435      c�g|]}t|���d��qS�r	)�_block_info_recursionrC��depth�	max_depthrQrrrF���z)_block_info_recursion.<locals>.<listcomp>cSs"g|]
\}}|D]}||�qqSrr)rDZslice_prefixZinner_slices�	the_slicerrrrF�s��r)rwry�	functools�reduce�operator�addrkrH)
436  r1rrQr~rP�slicesr@rHrxrErr}rr|{s�
437  ��
438  
439  r|cs:��kr���fdd�|D�}t|��d�St|��S)aZ
440      Internal implementation of block based on repeated concatenation.
441      `arrays` is the argument passed to
442      block. `max_depth` is the depth of nested lists within `arrays` and
443      `result_ndim` is the greatest of the dimensions of the arrays in
444      `arrays` and the depth of the lists in `arrays` (see block docstring
445      for details).
446      crzr{)�_blockrCr}rrrF�r�z_block.<locals>.<listcomp>rq)�_concatenaterk)r1rrQr~r>rr}rr��s	�
447  r�ccs4�t|�tur|D]	}t|�EdHq	dS|VdSr)r^r;�_block_dispatcher)r1Z	subarraysrrrr��s��
448  r�cCs4t|�\}}}}||dkrt|||�St|||�S)ap
449      Assemble an nd-array from nested lists of blocks.
450  
451      Blocks in the innermost lists are concatenated (see `concatenate`) along
452      the last dimension (-1), then these are concatenated along the
453      second-last dimension (-2), and so on until the outermost list is reached.
454  
455      Blocks can be of any dimension, but will not be broadcasted using the normal
456      rules. Instead, leading axes of size 1 are inserted, to make ``block.ndim``
457      the same for all blocks. This is primarily useful for working with scalars,
458      and means that code like ``np.block([v, 1])`` is valid, where
459      ``v.ndim == 1``.
460  
461      When the nested list is two levels deep, this allows block matrices to be
462      constructed from their components.
463  
464      .. versionadded:: 1.13.0
465  
466      Parameters
467      ----------
468      arrays : nested list of array_like or scalars (but not tuples)
469          If passed a single ndarray or scalar (a nested list of depth 0), this
470          is returned unmodified (and not copied).
471  
472          Elements shapes must match along the appropriate axes (without
473          broadcasting), but leading 1s will be prepended to the shape as
474          necessary to make the dimensions match.
475  
476      Returns
477      -------
478      block_array : ndarray
479          The array assembled from the given blocks.
480  
481          The dimensionality of the output is equal to the greatest of:
482          * the dimensionality of all the inputs
483          * the depth to which the input list is nested
484  
485      Raises
486      ------
487      ValueError
488          * If list depths are mismatched - for instance, ``[[a, b], c]`` is
489            illegal, and should be spelt ``[[a, b], [c]]``
490          * If lists are empty - for instance, ``[[a, b], []]``
491  
492      See Also
493      --------
494      concatenate : Join a sequence of arrays along an existing axis.
495      stack : Join a sequence of arrays along a new axis.
496      vstack : Stack arrays in sequence vertically (row wise).
497      hstack : Stack arrays in sequence horizontally (column wise).
498      dstack : Stack arrays in sequence depth wise (along third axis).
499      column_stack : Stack 1-D arrays as columns into a 2-D array.
500      vsplit : Split an array into multiple sub-arrays vertically (row-wise).
501  
502      Notes
503      -----
504  
505      When called with only scalars, ``np.block`` is equivalent to an ndarray
506      call. So ``np.block([[1, 2], [3, 4]])`` is equivalent to
507      ``np.array([[1, 2], [3, 4]])``.
508  
509      This function does not enforce that the blocks lie on a fixed grid.
510      ``np.block([[a, b], [c, d]])`` is not restricted to arrays of the form::
511  
512          AAAbb
513          AAAbb
514          cccDD
515  
516      But is also allowed to produce, for some ``a, b, c, d``::
517  
518          AAAbb
519          AAAbb
520          cDDDD
521  
522      Since concatenation happens along the last axis first, `block` is _not_
523      capable of producing the following directly::
524  
525          AAAbb
526          cccbb
527          cccDD
528  
529      Matlab's "square bracket stacking", ``[A, B, ...; p, q, ...]``, is
530      equivalent to ``np.block([[A, B, ...], [p, q, ...]])``.
531  
532      Examples
533      --------
534      The most common use of this function is to build a block matrix
535  
536      >>> A = np.eye(2) * 2
537      >>> B = np.eye(3) * 3
538      >>> np.block([
539      ...     [A,               np.zeros((2, 3))],
540      ...     [np.ones((3, 2)), B               ]
541      ... ])
542      array([[2., 0., 0., 0., 0.],
543             [0., 2., 0., 0., 0.],
544             [1., 1., 3., 0., 0.],
545             [1., 1., 0., 3., 0.],
546             [1., 1., 0., 0., 3.]])
547  
548      With a list of depth 1, `block` can be used as `hstack`
549  
550      >>> np.block([1, 2, 3])              # hstack([1, 2, 3])
551      array([1, 2, 3])
552  
553      >>> a = np.array([1, 2, 3])
554      >>> b = np.array([4, 5, 6])
555      >>> np.block([a, b, 10])             # hstack([a, b, 10])
556      array([ 1,  2,  3,  4,  5,  6, 10])
557  
558      >>> A = np.ones((2, 2), int)
559      >>> B = 2 * A
560      >>> np.block([A, B])                 # hstack([A, B])
561      array([[1, 1, 2, 2],
562             [1, 1, 2, 2]])
563  
564      With a list of depth 2, `block` can be used in place of `vstack`:
565  
566      >>> a = np.array([1, 2, 3])
567      >>> b = np.array([4, 5, 6])
568      >>> np.block([[a], [b]])             # vstack([a, b])
569      array([[1, 2, 3],
570             [4, 5, 6]])
571  
572      >>> A = np.ones((2, 2), int)
573      >>> B = 2 * A
574      >>> np.block([[A], [B]])             # vstack([A, B])
575      array([[1, 1],
576             [1, 1],
577             [2, 2],
578             [2, 2]])
579  
580      It can also be used in places of `atleast_1d` and `atleast_2d`
581  
582      >>> a = np.array(0)
583      >>> b = np.array([1])
584      >>> np.block([a])                    # atleast_1d(a)
585      array([0])
586      >>> np.block([b])                    # atleast_1d(b)
587      array([1])
588  
589      >>> np.block([[a]])                  # atleast_2d(a)
590      array([[0]])
591      >>> np.block([[b]])                  # atleast_2d(b)
592      array([[1]])
593  
594  
595      i)�_block_setup�_block_slicing�_block_concatenate)r1�	list_ndimrQrerrrr�s
596  rcCsNt|�\}}}t|�}|r|ddurtd�t|����t||�}||||fS)zD
597      Returns
598      (`arrays`, list_ndim, result_ndim, final_size)
599      r]NzList at {} cannot be empty)rZrrNrTrY�max)r1Zbottom_indexZarr_ndimrer�rQrrrr�~s��
600  r�cCs�t|||�\}}}tjdd�|D��}tdd�|D��}tdd�|D��}|r+|s+dnd}tj|||d�}	t||�D]\}
601  }||	tf|
602  <q:|	S)	NcSsg|]}|j�qSr)r4rCrrrrF�rJz"_block_slicing.<locals>.<listcomp>cs��|]}|jdVqdS)�F_CONTIGUOUSN��flagsrCrrrrV���z!_block_slicing.<locals>.<genexpr>csr�)�C_CONTIGUOUSNr�rCrrrrV�r��F�C)rHr4�order)r|r$�result_type�all�emptyrw�Ellipsis)r1r�rQrHr�r4ZF_orderZC_orderr�r!r�rErrrr��s
603  �r�cCs t|||�}|dkr|��}|S)Nr)r�rh)r1r�rQr!rrrr��sr�)r()NN)rN)r)0�__all__r�rlr�r.rSr
604  r$r�
605  multiarrayrr
rr�_from_nx�partial�array_function_dispatchrrr"rr&rr2r7rrrBr�getattrrfrcrrdr<r�rYrZrkroryr|r�r�rr�r�r�rrrr�<module>sh�
606  5
607  5
608  
609  C�KI�
610  ^�L
611  9
612  5
613  0