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

  2  [��cc��@s*ddlZddlmmZddlmZmZmZmZm	Z	m
  3  Z
  4  ddlmZm
Z
ddlmZddlmZddlmZmZddlmZddlmZdd	lmZdd
  5  lmZgd�Zejejdd
�Zdd�Zdd�Zee�dd��Z dd�Z!ee!�dd��Z"dd�Z#ee#�dd��Z$dd�Z%ee%�dd��Z&d d!�Z'ee'�d"d#��Z(eZ)d$d%�Z*ee*�d&d'��Z+d(d)�Z,ee,�d*d+��Z-d,d-�Z.dJd.d/�Z/ee/�dKd0d1��Z0dJd2d3�Z1ee1�dKd4d5��Z2d6d7�Z3ee3�d8d9��Z4ee3�d:d;��Z5ee3�d<d=��Z6d>d?�Z7d@dA�Z8dBdC�Z9ee9�dDdE��Z:dFdG�Z;ee;�dHdI��Z<dS)L�N)�asarray�zeros�outer�concatenate�array�
  6  asanyarray)�reshape�	transpose)�normalize_axis_index)�	overrides)�vstack�
  7  atleast_3d)�normalize_axis_tuple��_arrays_for_stack_dispatcher)�ndindex)�matrix)�column_stack�	row_stack�dstack�array_split�split�hsplit�vsplit�dsplit�apply_over_axes�expand_dims�apply_along_axis�kron�tile�get_array_wrap�take_along_axis�put_along_axis�numpy)�modulec	Cs�t�|jtj�std��t|�|jkrtd��d|j}tt	|��dgtt	|d|j��}g}t
  8  ||�D])\}}|durD|�|�q6|d|�d||dd�}|�t�|��
|��q6t|�S)Nz"`indices` must be an integer arrayz;`indices` and `arr` must have the same number of dimensions��r&)�����)�_nx�
  9  issubdtype�dtype�integer�
 10  IndexError�len�ndim�
 11  ValueError�list�range�zip�append�aranger�tuple)	�	arr_shape�indices�axisZ
 12  shape_onesZ	dest_dimsZfancy_index�dim�nZ	ind_shape�r;��C:\Users\Jacks.GUTTSPC\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\numpy\lib\shape_base.py�_make_along_axis_idxs�
 13  & r=cC�||fS�Nr;)�arrr7r8r;r;r<�_take_along_axis_dispatcher4�rAcCs@|dur|j}t|�f}d}n	t||j�}|j}|t|||�S)aw
 14      Take values from the input array by matching 1d index and data slices.
 15  
 16      This iterates over matching 1d slices oriented along the specified axis in
 17      the index and data arrays, and uses the former to look up values in the
 18      latter. These slices can be different lengths.
 19  
 20      Functions returning an index along an axis, like `argsort` and
 21      `argpartition`, produce suitable indices for this function.
 22  
 23      .. versionadded:: 1.15.0
 24  
 25      Parameters
 26      ----------
 27      arr : ndarray (Ni..., M, Nk...)
 28          Source array
 29      indices : ndarray (Ni..., J, Nk...)
 30          Indices to take along each 1d slice of `arr`. This must match the
 31          dimension of arr, but dimensions Ni and Nj only need to broadcast
 32          against `arr`.
 33      axis : int
 34          The axis to take 1d slices along. If axis is None, the input array is
 35          treated as if it had first been flattened to 1d, for consistency with
 36          `sort` and `argsort`.
 37  
 38      Returns
 39      -------
 40      out: ndarray (Ni..., J, Nk...)
 41          The indexed result.
 42  
 43      Notes
 44      -----
 45      This is equivalent to (but faster than) the following use of `ndindex` and
 46      `s_`, which sets each of ``ii`` and ``kk`` to a tuple of indices::
 47  
 48          Ni, M, Nk = a.shape[:axis], a.shape[axis], a.shape[axis+1:]
 49          J = indices.shape[axis]  # Need not equal M
 50          out = np.empty(Ni + (J,) + Nk)
 51  
 52          for ii in ndindex(Ni):
 53              for kk in ndindex(Nk):
 54                  a_1d       = a      [ii + s_[:,] + kk]
 55                  indices_1d = indices[ii + s_[:,] + kk]
 56                  out_1d     = out    [ii + s_[:,] + kk]
 57                  for j in range(J):
 58                      out_1d[j] = a_1d[indices_1d[j]]
 59  
 60      Equivalently, eliminating the inner loop, the last two lines would be::
 61  
 62                  out_1d[:] = a_1d[indices_1d]
 63  
 64      See Also
 65      --------
 66      take : Take along an axis, using the same indices for every 1d slice
 67      put_along_axis :
 68          Put values into the destination array by matching 1d index and data slices
 69  
 70      Examples
 71      --------
 72  
 73      For this sample array
 74  
 75      >>> a = np.array([[10, 30, 20], [60, 40, 50]])
 76  
 77      We can sort either by using sort directly, or argsort and this function
 78  
 79      >>> np.sort(a, axis=1)
 80      array([[10, 20, 30],
 81             [40, 50, 60]])
 82      >>> ai = np.argsort(a, axis=1); ai
 83      array([[0, 2, 1],
 84             [1, 2, 0]])
 85      >>> np.take_along_axis(a, ai, axis=1)
 86      array([[10, 20, 30],
 87             [40, 50, 60]])
 88  
 89      The same works for max and min, if you expand the dimensions:
 90  
 91      >>> np.expand_dims(np.max(a, axis=1), axis=1)
 92      array([[30],
 93             [60]])
 94      >>> ai = np.expand_dims(np.argmax(a, axis=1), axis=1)
 95      >>> ai
 96      array([[1],
 97             [0]])
 98      >>> np.take_along_axis(a, ai, axis=1)
 99      array([[30],
100             [60]])
101  
102      If we want to get the max and min at the same time, we can stack the
103      indices first
104  
105      >>> ai_min = np.expand_dims(np.argmin(a, axis=1), axis=1)
106      >>> ai_max = np.expand_dims(np.argmax(a, axis=1), axis=1)
107      >>> ai = np.concatenate([ai_min, ai_max], axis=1)
108      >>> ai
109      array([[0, 1],
110             [1, 0]])
111      >>> np.take_along_axis(a, ai, axis=1)
112      array([[10, 30],
113             [40, 60]])
114      Nr��flatr-r
115  r.�shaper=)r@r7r8r6r;r;r<r!8si
116  r!cCs
117  |||fSr?r;)r@r7�valuesr8r;r;r<�_put_along_axis_dispatcher�s
118  rGcCsD|dur|j}d}t|�f}n	t||j�}|j}||t|||�<dS)a	
119      Put values into the destination array by matching 1d index and data slices.
120  
121      This iterates over matching 1d slices oriented along the specified axis in
122      the index and data arrays, and uses the former to place values into the
123      latter. These slices can be different lengths.
124  
125      Functions returning an index along an axis, like `argsort` and
126      `argpartition`, produce suitable indices for this function.
127  
128      .. versionadded:: 1.15.0
129  
130      Parameters
131      ----------
132      arr : ndarray (Ni..., M, Nk...)
133          Destination array.
134      indices : ndarray (Ni..., J, Nk...)
135          Indices to change along each 1d slice of `arr`. This must match the
136          dimension of arr, but dimensions in Ni and Nj may be 1 to broadcast
137          against `arr`.
138      values : array_like (Ni..., J, Nk...)
139          values to insert at those indices. Its shape and dimension are
140          broadcast to match that of `indices`.
141      axis : int
142          The axis to take 1d slices along. If axis is None, the destination
143          array is treated as if a flattened 1d view had been created of it.
144  
145      Notes
146      -----
147      This is equivalent to (but faster than) the following use of `ndindex` and
148      `s_`, which sets each of ``ii`` and ``kk`` to a tuple of indices::
149  
150          Ni, M, Nk = a.shape[:axis], a.shape[axis], a.shape[axis+1:]
151          J = indices.shape[axis]  # Need not equal M
152  
153          for ii in ndindex(Ni):
154              for kk in ndindex(Nk):
155                  a_1d       = a      [ii + s_[:,] + kk]
156                  indices_1d = indices[ii + s_[:,] + kk]
157                  values_1d  = values [ii + s_[:,] + kk]
158                  for j in range(J):
159                      a_1d[indices_1d[j]] = values_1d[j]
160  
161      Equivalently, eliminating the inner loop, the last two lines would be::
162  
163                  a_1d[indices_1d] = values_1d
164  
165      See Also
166      --------
167      take_along_axis :
168          Take values from the input array by matching 1d index and data slices
169  
170      Examples
171      --------
172  
173      For this sample array
174  
175      >>> a = np.array([[10, 30, 20], [60, 40, 50]])
176  
177      We can replace the maximum values with:
178  
179      >>> ai = np.expand_dims(np.argmax(a, axis=1), axis=1)
180      >>> ai
181      array([[1],
182             [0]])
183      >>> np.put_along_axis(a, ai, 99, axis=1)
184      >>> a
185      array([[10, 99, 20],
186             [99, 40, 50]])
187  
188      NrrC)r@r7rFr8r6r;r;r<r"�sJr"cOs|fSr?r;)�func1dr8r@�args�kwargsr;r;r<�_apply_along_axis_dispatcher�rKc
189  Os�t|�}|j}t||�}tt|��}t||d|�||dd�|g�}t|jdd��}dd�|D�}zt|�}	Wnt	yM}
190  zt
191  d�d�d}
192  ~
193  wwt|||	g|�Ri|���}t|jdd�|j|j�}tt|j��}
|
d|�|
|j|j|j�|
||j|j�}t
|t�s�|�|�}|||	<|D]}t|||g|�Ri|���||<q�t
|t�s�|�|�}t||�St||�}|�|�S)aU
194      Apply a function to 1-D slices along the given axis.
195  
196      Execute `func1d(a, *args, **kwargs)` where `func1d` operates on 1-D arrays
197      and `a` is a 1-D slice of `arr` along `axis`.
198  
199      This is equivalent to (but faster than) the following use of `ndindex` and
200      `s_`, which sets each of ``ii``, ``jj``, and ``kk`` to a tuple of indices::
201  
202          Ni, Nk = a.shape[:axis], a.shape[axis+1:]
203          for ii in ndindex(Ni):
204              for kk in ndindex(Nk):
205                  f = func1d(arr[ii + s_[:,] + kk])
206                  Nj = f.shape
207                  for jj in ndindex(Nj):
208                      out[ii + jj + kk] = f[jj]
209  
210      Equivalently, eliminating the inner loop, this can be expressed as::
211  
212          Ni, Nk = a.shape[:axis], a.shape[axis+1:]
213          for ii in ndindex(Ni):
214              for kk in ndindex(Nk):
215                  out[ii + s_[...,] + kk] = func1d(arr[ii + s_[:,] + kk])
216  
217      Parameters
218      ----------
219      func1d : function (M,) -> (Nj...)
220          This function should accept 1-D arrays. It is applied to 1-D
221          slices of `arr` along the specified axis.
222      axis : integer
223          Axis along which `arr` is sliced.
224      arr : ndarray (Ni..., M, Nk...)
225          Input array.
226      args : any
227          Additional arguments to `func1d`.
228      kwargs : any
229          Additional named arguments to `func1d`.
230  
231          .. versionadded:: 1.9.0
232  
233  
234      Returns
235      -------
236      out : ndarray  (Ni..., Nj..., Nk...)
237          The output array. The shape of `out` is identical to the shape of
238          `arr`, except along the `axis` dimension. This axis is removed, and
239          replaced with new dimensions equal to the shape of the return value
240          of `func1d`. So if `func1d` returns a scalar `out` will have one
241          fewer dimensions than `arr`.
242  
243      See Also
244      --------
245      apply_over_axes : Apply a function repeatedly over multiple axes.
246  
247      Examples
248      --------
249      >>> def my_func(a):
250      ...     """Average first and last element of a 1-D array"""
251      ...     return (a[0] + a[-1]) * 0.5
252      >>> b = np.array([[1,2,3], [4,5,6], [7,8,9]])
253      >>> np.apply_along_axis(my_func, 0, b)
254      array([4., 5., 6.])
255      >>> np.apply_along_axis(my_func, 1, b)
256      array([2.,  5.,  8.])
257  
258      For a function that returns a 1D array, the number of dimensions in
259      `outarr` is the same as `arr`.
260  
261      >>> b = np.array([[8,1,7], [4,3,9], [5,2,6]])
262      >>> np.apply_along_axis(sorted, 1, b)
263      array([[1, 7, 8],
264             [3, 4, 9],
265             [2, 5, 6]])
266  
267      For a function that returns a higher dimensional array, those dimensions
268      are inserted in place of the `axis` dimension.
269  
270      >>> b = np.array([[1,2,3], [4,5,6], [7,8,9]])
271      >>> np.apply_along_axis(np.diag, -1, b)
272      array([[[1, 0, 0],
273              [0, 2, 0],
274              [0, 0, 3]],
275             [[4, 0, 0],
276              [0, 5, 0],
277              [0, 0, 6]],
278             [[7, 0, 0],
279              [0, 8, 0],
280              [0, 0, 9]]])
281      Nr&r'css�|]}|tfVqdSr?)�Ellipsis)�.0�indr;r;r<�	<genexpr>rs�z#apply_along_axis.<locals>.<genexpr>z;Cannot apply_along_axis when any iteration dimensions are 0r)rr.r
282  r0r1r	rrE�next�
StopIterationr/rr*�
283  isinstancer�__array_prepare__�__array_wrap__)rHr8r@rIrJ�ndZin_dimsZ
284  inarr_view�indsZind0�e�res�buffZ	buff_dimsZbuff_permuterO�out_arrr;r;r<rsH\
285  (����
286  ���
287  
288  $
289  
290  
291  
292  
293  rcCs|fSr?r;)�func�a�axesr;r;r<�_apply_over_axes_dispatcher�rLr_cCs�t|�}|j}t|�jdkr|f}|D],}|dkr||}||f}||�}|j|jkr.|}qt||�}|j|jkr<|}qtd��|S)ay
294      Apply a function repeatedly over multiple axes.
295  
296      `func` is called as `res = func(a, axis)`, where `axis` is the first
297      element of `axes`.  The result `res` of the function call must have
298      either the same dimensions as `a` or one less dimension.  If `res`
299      has one less dimension than `a`, a dimension is inserted before
300      `axis`.  The call to `func` is then repeated for each axis in `axes`,
301      with `res` as the first argument.
302  
303      Parameters
304      ----------
305      func : function
306          This function must take two arguments, `func(a, axis)`.
307      a : array_like
308          Input array.
309      axes : array_like
310          Axes over which `func` is applied; the elements must be integers.
311  
312      Returns
313      -------
314      apply_over_axis : ndarray
315          The output array.  The number of dimensions is the same as `a`,
316          but the shape can be different.  This depends on whether `func`
317          changes the shape of its output with respect to its input.
318  
319      See Also
320      --------
321      apply_along_axis :
322          Apply a function to 1-D slices of an array along the given axis.
323  
324      Notes
325      -----
326      This function is equivalent to tuple axis arguments to reorderable ufuncs
327      with keepdims=True. Tuple axis arguments to ufuncs have been available since
328      version 1.7.0.
329  
330      Examples
331      --------
332      >>> a = np.arange(24).reshape(2,3,4)
333      >>> a
334      array([[[ 0,  1,  2,  3],
335              [ 4,  5,  6,  7],
336              [ 8,  9, 10, 11]],
337             [[12, 13, 14, 15],
338              [16, 17, 18, 19],
339              [20, 21, 22, 23]]])
340  
341      Sum over axes 0 and 2. The result has same number of dimensions
342      as the original array:
343  
344      >>> np.apply_over_axes(np.sum, a, [0,2])
345      array([[[ 60],
346              [ 92],
347              [124]]])
348  
349      Tuple axis arguments to ufuncs are equivalent:
350  
351      >>> np.sum(a, axis=(0,2), keepdims=True)
352      array([[[ 60],
353              [ 92],
354              [124]]])
355  
356      rz7function is not returning an array of the correct shape)rr.rrr/)r\r]r^�val�Nr8rIrYr;r;r<r�s B
357  rcCs|fSr?r;)r]r8r;r;r<�_expand_dims_dispatcher�rLrbcsvt|t�r
358  t|�}nt|�}t��ttfvr�f�t��|j}t	�|��t
359  |j����fdd�t|�D�}|�
|�S)a.
360      Expand the shape of an array.
361  
362      Insert a new axis that will appear at the `axis` position in the expanded
363      array shape.
364  
365      Parameters
366      ----------
367      a : array_like
368          Input array.
369      axis : int or tuple of ints
370          Position in the expanded axes where the new axis (or axes) is placed.
371  
372          .. deprecated:: 1.13.0
373              Passing an axis where ``axis > a.ndim`` will be treated as
374              ``axis == a.ndim``, and passing ``axis < -a.ndim - 1`` will
375              be treated as ``axis == 0``. This behavior is deprecated.
376  
377          .. versionchanged:: 1.18.0
378              A tuple of axes is now supported.  Out of range axes as
379              described above are now forbidden and raise an `AxisError`.
380  
381      Returns
382      -------
383      result : ndarray
384          View of `a` with the number of dimensions increased.
385  
386      See Also
387      --------
388      squeeze : The inverse operation, removing singleton dimensions
389      reshape : Insert, remove, and combine dimensions, and resize existing ones
390      doc.indexing, atleast_1d, atleast_2d, atleast_3d
391  
392      Examples
393      --------
394      >>> x = np.array([1, 2])
395      >>> x.shape
396      (2,)
397  
398      The following is equivalent to ``x[np.newaxis, :]`` or ``x[np.newaxis]``:
399  
400      >>> y = np.expand_dims(x, axis=0)
401      >>> y
402      array([[1, 2]])
403      >>> y.shape
404      (1, 2)
405  
406      The following is equivalent to ``x[:, np.newaxis]``:
407  
408      >>> y = np.expand_dims(x, axis=1)
409      >>> y
410      array([[1],
411             [2]])
412      >>> y.shape
413      (2, 1)
414  
415      ``axis`` may also be a tuple:
416  
417      >>> y = np.expand_dims(x, axis=(0, 1))
418      >>> y
419      array([[[1, 2]]])
420  
421      >>> y = np.expand_dims(x, axis=(2, 0))
422      >>> y
423      array([[[1],
424              [2]]])
425  
426      Note that some examples may use ``None`` instead of ``np.newaxis``.  These
427      are the same objects:
428  
429      >>> np.newaxis is None
430      True
431  
432      cs g|]}|�vr
433  dnt���qSr%)rQ)rN�ax�r8Zshape_itr;r<�
434  <listcomp>Xs zexpand_dims.<locals>.<listcomp>)rSrrr�typer5r0r-r.r�iterrEr1r)r]r8Zout_ndimrEr;rdr<rs
435  L
436  
437  
438  
439  rcC�t|�Sr?r��tupr;r;r<�_column_stack_dispatcher`rBrkcCsZtjs	t|dd�g}|D]}t|�}|jdkr!t|dddd�j}|�|�q
t�	|d�S)a�
440      Stack 1-D arrays as columns into a 2-D array.
441  
442      Take a sequence of 1-D arrays and stack them as columns
443      to make a single 2-D array. 2-D arrays are stacked as-is,
444      just like with `hstack`.  1-D arrays are turned into 2-D columns
445      first.
446  
447      Parameters
448      ----------
449      tup : sequence of 1-D or 2-D arrays.
450          Arrays to stack. All of them must have the same first dimension.
451  
452      Returns
453      -------
454      stacked : 2-D array
455          The array formed by stacking the given arrays.
456  
457      See Also
458      --------
459      stack, hstack, vstack, concatenate
460  
461      Examples
462      --------
463      >>> a = np.array((1,2,3))
464      >>> b = np.array((2,3,4))
465      >>> np.column_stack((a,b))
466      array([[1, 2],
467             [2, 3],
468             [3, 4]])
469  
470      ���
471  stacklevelFT��copy�subok�ndminr&)
472  r�ARRAY_FUNCTION_ENABLEDrrr.r�Tr3r(r)rj�arrays�vr@r;r;r<rds"
473  rcCrhr?rrir;r;r<�_dstack_dispatcher�rBrwcCs6tjs	t|dd�t|�}t|t�s|g}t�|d�S)a�
474      Stack arrays in sequence depth wise (along third axis).
475  
476      This is equivalent to concatenation along the third axis after 2-D arrays
477      of shape `(M,N)` have been reshaped to `(M,N,1)` and 1-D arrays of shape
478      `(N,)` have been reshaped to `(1,N,1)`. Rebuilds arrays divided by
479      `dsplit`.
480  
481      This function makes most sense for arrays with up to 3 dimensions. For
482      instance, for pixel-data with a height (first axis), width (second axis),
483      and r/g/b channels (third axis). The functions `concatenate`, `stack` and
484      `block` provide more general stacking and concatenation operations.
485  
486      Parameters
487      ----------
488      tup : sequence of arrays
489          The arrays must have the same shape along all but the third axis.
490          1-D or 2-D arrays must have the same shape.
491  
492      Returns
493      -------
494      stacked : ndarray
495          The array formed by stacking the given arrays, will be at least 3-D.
496  
497      See Also
498      --------
499      concatenate : Join a sequence of arrays along an existing axis.
500      stack : Join a sequence of arrays along a new axis.
501      block : Assemble an nd-array from nested lists of blocks.
502      vstack : Stack arrays in sequence vertically (row wise).
503      hstack : Stack arrays in sequence horizontally (column wise).
504      column_stack : Stack 1-D arrays as columns into a 2-D array.
505      dsplit : Split array along third axis.
506  
507      Examples
508      --------
509      >>> a = np.array((1,2,3))
510      >>> b = np.array((2,3,4))
511      >>> np.dstack((a,b))
512      array([[[1, 2],
513              [2, 3],
514              [3, 4]]])
515  
516      >>> a = np.array([[1],[2],[3]])
517      >>> b = np.array([[2],[3],[4]])
518      >>> np.dstack((a,b))
519      array([[[1, 2]],
520             [[2, 3]],
521             [[3, 4]]])
522  
523      rlrm)rrsrr
rSr0r(r)rj�arrsr;r;r<r�s5
524  rc	Csvtt|��D]2}t�||�dkrtjd||jd�||<qt�t�t�||�d��r8tjd||jd�||<q|S)Nr�r*)	r1r-r(r.�emptyr*�sometrue�equalrE)�sub_arys�ir;r;r<�_replace_zero_by_x_arrays�s�rcCr>r?r;��ary�indices_or_sectionsr8r;r;r<�_array_split_dispatcher�rBr�cCsz|j|}Wn
tyt|�}Ynwzt|�d}dgt|�|g}Wn8ty_t|�}|dkr;td�d�t||�\}}dg||dg|||g}tj	|tj
525  d���}Ynwg}	t�||d�}
526  t
|�D]}||}||d}
|	�t�|
527  ||
�|d��qm|	S)a
528  
529      Split an array into multiple sub-arrays.
530  
531      Please refer to the ``split`` documentation.  The only difference
532      between these functions is that ``array_split`` allows
533      `indices_or_sections` to be an integer that does *not* equally
534      divide the axis. For an array of length l that should be split
535      into n sections, it returns l % n sub-arrays of size l//n + 1
536      and the rest of size l//n.
537  
538      See Also
539      --------
540      split : Split array into multiple sub-arrays of equal size.
541  
542      Examples
543      --------
544      >>> x = np.arange(8.0)
545      >>> np.array_split(x, 3)
546      [array([0.,  1.,  2.]), array([3.,  4.,  5.]), array([6.,  7.])]
547  
548      >>> x = np.arange(9)
549      >>> np.array_split(x, 4)
550      [array([0, 1, 2]), array([3, 4]), array([5, 6]), array([7, 8])]
551  
552      r&rz&number sections must be larger than 0.Nry)rE�AttributeErrorr-r0�	TypeError�intr/�divmodr(r�intp�cumsum�swapaxesr1r3)r�r�r8ZNtotalZ	NsectionsZ
553  div_pointsZ
Neach_section�extrasZ
section_sizesr}Zsaryr~�st�endr;r;r<r�s6�
554  ���rcCr>r?r;r�r;r;r<�_split_dispatcherrBr�cCsLzt|�Wnty|}|j|}||rtd�d�Ynwt|||�S)a�
555      Split an array into multiple sub-arrays as views into `ary`.
556  
557      Parameters
558      ----------
559      ary : ndarray
560          Array to be divided into sub-arrays.
561      indices_or_sections : int or 1-D array
562          If `indices_or_sections` is an integer, N, the array will be divided
563          into N equal arrays along `axis`.  If such a split is not possible,
564          an error is raised.
565  
566          If `indices_or_sections` is a 1-D array of sorted integers, the entries
567          indicate where along `axis` the array is split.  For example,
568          ``[2, 3]`` would, for ``axis=0``, result in
569  
570            - ary[:2]
571            - ary[2:3]
572            - ary[3:]
573  
574          If an index exceeds the dimension of the array along `axis`,
575          an empty sub-array is returned correspondingly.
576      axis : int, optional
577          The axis along which to split, default is 0.
578  
579      Returns
580      -------
581      sub-arrays : list of ndarrays
582          A list of sub-arrays as views into `ary`.
583  
584      Raises
585      ------
586      ValueError
587          If `indices_or_sections` is given as an integer, but
588          a split does not result in equal division.
589  
590      See Also
591      --------
592      array_split : Split an array into multiple sub-arrays of equal or
593                    near-equal size.  Does not raise an exception if
594                    an equal division cannot be made.
595      hsplit : Split array into multiple sub-arrays horizontally (column-wise).
596      vsplit : Split array into multiple sub-arrays vertically (row wise).
597      dsplit : Split array into multiple sub-arrays along the 3rd axis (depth).
598      concatenate : Join a sequence of arrays along an existing axis.
599      stack : Join a sequence of arrays along a new axis.
600      hstack : Stack arrays in sequence horizontally (column wise).
601      vstack : Stack arrays in sequence vertically (row wise).
602      dstack : Stack arrays in sequence depth wise (along third dimension).
603  
604      Examples
605      --------
606      >>> x = np.arange(9.0)
607      >>> np.split(x, 3)
608      [array([0.,  1.,  2.]), array([3.,  4.,  5.]), array([6.,  7.,  8.])]
609  
610      >>> x = np.arange(8.0)
611      >>> np.split(x, [3, 5, 6, 10])
612      [array([0.,  1.,  2.]),
613       array([3.,  4.]),
614       array([5.]),
615       array([6.,  7.]),
616       array([], dtype=float64)]
617  
618      z0array split does not result in an equal divisionN)r-r�rEr/r)r�r�r8�sectionsrar;r;r<rsC
619  ����rcCr>r?r;�r�r�r;r;r<�_hvdsplit_dispatchermrBr�cCs8t�|�dkrtd��|jdkrt||d�St||d�S)a]
620      Split an array into multiple sub-arrays horizontally (column-wise).
621  
622      Please refer to the `split` documentation.  `hsplit` is equivalent
623      to `split` with ``axis=1``, the array is always split along the second
624      axis except for 1-D arrays, where it is split at ``axis=0``.
625  
626      See Also
627      --------
628      split : Split an array into multiple sub-arrays of equal size.
629  
630      Examples
631      --------
632      >>> x = np.arange(16.0).reshape(4, 4)
633      >>> x
634      array([[ 0.,   1.,   2.,   3.],
635             [ 4.,   5.,   6.,   7.],
636             [ 8.,   9.,  10.,  11.],
637             [12.,  13.,  14.,  15.]])
638      >>> np.hsplit(x, 2)
639      [array([[  0.,   1.],
640             [  4.,   5.],
641             [  8.,   9.],
642             [12.,  13.]]),
643       array([[  2.,   3.],
644             [  6.,   7.],
645             [10.,  11.],
646             [14.,  15.]])]
647      >>> np.hsplit(x, np.array([3, 6]))
648      [array([[ 0.,   1.,   2.],
649             [ 4.,   5.,   6.],
650             [ 8.,   9.,  10.],
651             [12.,  13.,  14.]]),
652       array([[ 3.],
653             [ 7.],
654             [11.],
655             [15.]]),
656       array([], shape=(4, 0), dtype=float64)]
657  
658      With a higher dimensional array the split is still along the second axis.
659  
660      >>> x = np.arange(8.0).reshape(2, 2, 2)
661      >>> x
662      array([[[0.,  1.],
663              [2.,  3.]],
664             [[4.,  5.],
665              [6.,  7.]]])
666      >>> np.hsplit(x, 2)
667      [array([[[0.,  1.]],
668             [[4.,  5.]]]),
669       array([[[2.,  3.]],
670             [[6.,  7.]]])]
671  
672      With a 1-D array, the split is along axis 0.
673  
674      >>> x = np.array([0, 1, 2, 3, 4, 5])
675      >>> np.hsplit(x, 2)
676      [array([0, 1, 2]), array([3, 4, 5])]
677  
678      rz3hsplit only works on arrays of 1 or more dimensionsr&�r(r.r/rr�r;r;r<rqs
679  >
680  rcC�"t�|�dkrtd��t||d�S)a
681      Split an array into multiple sub-arrays vertically (row-wise).
682  
683      Please refer to the ``split`` documentation.  ``vsplit`` is equivalent
684      to ``split`` with `axis=0` (default), the array is always split along the
685      first axis regardless of the array dimension.
686  
687      See Also
688      --------
689      split : Split an array into multiple sub-arrays of equal size.
690  
691      Examples
692      --------
693      >>> x = np.arange(16.0).reshape(4, 4)
694      >>> x
695      array([[ 0.,   1.,   2.,   3.],
696             [ 4.,   5.,   6.,   7.],
697             [ 8.,   9.,  10.,  11.],
698             [12.,  13.,  14.,  15.]])
699      >>> np.vsplit(x, 2)
700      [array([[0., 1., 2., 3.],
701             [4., 5., 6., 7.]]), array([[ 8.,  9., 10., 11.],
702             [12., 13., 14., 15.]])]
703      >>> np.vsplit(x, np.array([3, 6]))
704      [array([[ 0.,  1.,  2.,  3.],
705             [ 4.,  5.,  6.,  7.],
706             [ 8.,  9., 10., 11.]]), array([[12., 13., 14., 15.]]), array([], shape=(0, 4), dtype=float64)]
707  
708      With a higher dimensional array the split is still along the first axis.
709  
710      >>> x = np.arange(8.0).reshape(2, 2, 2)
711      >>> x
712      array([[[0.,  1.],
713              [2.,  3.]],
714             [[4.,  5.],
715              [6.,  7.]]])
716      >>> np.vsplit(x, 2)
717      [array([[[0., 1.],
718              [2., 3.]]]), array([[[4., 5.],
719              [6., 7.]]])]
720  
721      rlz3vsplit only works on arrays of 2 or more dimensionsrr�r�r;r;r<r�s,rcCr�)am
722      Split array into multiple sub-arrays along the 3rd axis (depth).
723  
724      Please refer to the `split` documentation.  `dsplit` is equivalent
725      to `split` with ``axis=2``, the array is always split along the third
726      axis provided the array dimension is greater than or equal to 3.
727  
728      See Also
729      --------
730      split : Split an array into multiple sub-arrays of equal size.
731  
732      Examples
733      --------
734      >>> x = np.arange(16.0).reshape(2, 2, 4)
735      >>> x
736      array([[[ 0.,   1.,   2.,   3.],
737              [ 4.,   5.,   6.,   7.]],
738             [[ 8.,   9.,  10.,  11.],
739              [12.,  13.,  14.,  15.]]])
740      >>> np.dsplit(x, 2)
741      [array([[[ 0.,  1.],
742              [ 4.,  5.]],
743             [[ 8.,  9.],
744              [12., 13.]]]), array([[[ 2.,  3.],
745              [ 6.,  7.]],
746             [[10., 11.],
747              [14., 15.]]])]
748      >>> np.dsplit(x, np.array([3, 6]))
749      [array([[[ 0.,   1.,   2.],
750              [ 4.,   5.,   6.]],
751             [[ 8.,   9.,  10.],
752              [12.,  13.,  14.]]]),
753       array([[[ 3.],
754              [ 7.]],
755             [[11.],
756              [15.]]]),
757      array([], shape=(2, 2, 0), dtype=float64)]
758      �z3dsplit only works on arrays of 3 or more dimensionsrlr�r�r;r;r<r�s(rcG�*tdd�t|�D��}|r|ddSdS)��Find the wrapper for the array with the highest priority.
759  
760      In case of ties, leftmost wins. If no wrapper is found, return None
761      cs�4�|]\}}t|d�rt|dd�||jfVqdS)rT�__array_priority__rN)�hasattr�getattrrT�rNr~�xr;r;r<rP����z$get_array_prepare.<locals>.<genexpr>r'N��sorted�	enumerate�rI�wrappersr;r;r<�get_array_prepare��r�cGr�)r�csr�)rUr�rN)r�r�rUr�r;r;r<rP%r�z!get_array_wrap.<locals>.<genexpr>r'Nr�r�r;r;r<r  r�r cCr>r?r;)r]�br;r;r<�_kron_dispatcher-rBr�cCs^t|�}t|dd|jd�}t|t�pt|t�}|j|j}}t||�}|dks+|dkr1t�||�S|j}|j}|j	j
762  s@t||�}|j	j
763  sIt||�}dtd||�|}dtd||�|}t|t
t||��d�}t|t
t||��d�}	t|t
td|dd��d�}t|	t
td|dd��d�}	tj||	|d	�}
764  |
765  �t�||��}
766  |s�|
767  St|
768  dd
769  �S)a
770      Kronecker product of two arrays.
771  
772      Computes the Kronecker product, a composite array made of blocks of the
773      second array scaled by the first.
774  
775      Parameters
776      ----------
777      a, b : array_like
778  
779      Returns
780      -------
781      out : ndarray
782  
783      See Also
784      --------
785      outer : The outer product
786  
787      Notes
788      -----
789      The function assumes that the number of dimensions of `a` and `b`
790      are the same, if necessary prepending the smallest with ones.
791      If ``a.shape = (r0,r1,..,rN)`` and ``b.shape = (s0,s1,...,sN)``,
792      the Kronecker product has shape ``(r0*s0, r1*s1, ..., rN*SN)``.
793      The elements are products of elements from `a` and `b`, organized
794      explicitly by::
795  
796          kron(a,b)[k0,k1,...,kN] = a[i0,i1,...,iN] * b[j0,j1,...,jN]
797  
798      where::
799  
800          kt = it * st + jt,  t = 0,...,N
801  
802      In the common 2-D case (N=1), the block structure can be visualized::
803  
804          [[ a[0,0]*b,   a[0,1]*b,  ... , a[0,-1]*b  ],
805           [  ...                              ...   ],
806           [ a[-1,0]*b,  a[-1,1]*b, ... , a[-1,-1]*b ]]
807  
808  
809      Examples
810      --------
811      >>> np.kron([1,10,100], [5,6,7])
812      array([  5,   6,   7, ..., 500, 600, 700])
813      >>> np.kron([5,6,7], [1,10,100])
814      array([  5,  50, 500, ...,   7,  70, 700])
815  
816      >>> np.kron(np.eye(2), np.ones((2,2)))
817      array([[1.,  1.,  0.,  0.],
818             [1.,  1.,  0.,  0.],
819             [0.,  0.,  1.,  1.],
820             [0.,  0.,  1.,  1.]])
821  
822      >>> a = np.arange(100).reshape((2,5,2,5))
823      >>> b = np.arange(24).reshape((2,3,4))
824      >>> c = np.kron(a,b)
825      >>> c.shape
826      (2, 10, 6, 20)
827      >>> I = (1,3,0,2)
828      >>> J = (0,2,1)
829      >>> J1 = (0,) + J             # extend to ndim=4
830      >>> S1 = (1,) + b.shape
831      >>> K = tuple(np.array(I) * np.array(S1) + np.array(J1))
832      >>> c[K] == a[I]*b[J]
833      True
834  
835      FTrorr%)r8r&rl)rq)rp)rrr.rSr�maxr(�multiplyrE�flags�
836  contiguousrrr5r1)r]r�Z
837  is_any_mat�ndb�ndarV�as_�bs�a_arrZb_arr�resultr;r;r<r1s,N
838  
839  
840  rcCr>r?r;)�A�repsr;r;r<�_tile_dispatcher�rBr�c	Cs�zt|�}Wnty|f}Ynwt|�}tdd�|D��r/t|tj�r/tj|dd|d�Stj|dd|d�}||jkrFd|j||}tdd�t	|j
841  |�D��}|j}|dkrwt	|j
842  |�D]\}}|d	krr|�d
843  |��
|d�}||}q`|�|�S)a
844      Construct an array by repeating A the number of times given by reps.
845  
846      If `reps` has length ``d``, the result will have dimension of
847      ``max(d, A.ndim)``.
848  
849      If ``A.ndim < d``, `A` is promoted to be d-dimensional by prepending new
850      axes. So a shape (3,) array is promoted to (1, 3) for 2-D replication,
851      or shape (1, 1, 3) for 3-D replication. If this is not the desired
852      behavior, promote `A` to d-dimensions manually before calling this
853      function.
854  
855      If ``A.ndim > d``, `reps` is promoted to `A`.ndim by pre-pending 1's to it.
856      Thus for an `A` of shape (2, 3, 4, 5), a `reps` of (2, 2) is treated as
857      (1, 1, 2, 2).
858  
859      Note : Although tile may be used for broadcasting, it is strongly
860      recommended to use numpy's broadcasting operations and functions.
861  
862      Parameters
863      ----------
864      A : array_like
865          The input array.
866      reps : array_like
867          The number of repetitions of `A` along each axis.
868  
869      Returns
870      -------
871      c : ndarray
872          The tiled output array.
873  
874      See Also
875      --------
876      repeat : Repeat elements of an array.
877      broadcast_to : Broadcast an array to a new shape
878  
879      Examples
880      --------
881      >>> a = np.array([0, 1, 2])
882      >>> np.tile(a, 2)
883      array([0, 1, 2, 0, 1, 2])
884      >>> np.tile(a, (2, 2))
885      array([[0, 1, 2, 0, 1, 2],
886             [0, 1, 2, 0, 1, 2]])
887      >>> np.tile(a, (2, 1, 2))
888      array([[[0, 1, 2, 0, 1, 2]],
889             [[0, 1, 2, 0, 1, 2]]])
890  
891      >>> b = np.array([[1, 2], [3, 4]])
892      >>> np.tile(b, 2)
893      array([[1, 2, 1, 2],
894             [3, 4, 3, 4]])
895      >>> np.tile(b, (2, 1))
896      array([[1, 2],
897             [3, 4],
898             [1, 2],
899             [3, 4]])
900  
901      >>> c = np.array([1,2,3,4])
902      >>> np.tile(c,(4,1))
903      array([[1, 2, 3, 4],
904             [1, 2, 3, 4],
905             [1, 2, 3, 4],
906             [1, 2, 3, 4]])
907      css�|]}|dkVqdS)r&Nr;)rNr�r;r;r<rP�s�ztile.<locals>.<genexpr>TroFr%css�|]	\}}||VqdSr?r;)rN�s�tr;r;r<rP�s�rr&r')r5r�r-�allrSr(�ndarrayrr.r2rE�sizer�repeat)	r�r�rj�d�c�	shape_outr:Zdim_in�nrepr;r;r<r�s&C
908  �
909  
910  
911  rr?)r)=�	functools�numpy.core.numeric�core�numericr(rrrrrr�numpy.core.fromnumericrr	�numpy.core.multiarrayr
912913  numpy.corerrr
r�numpy.core.shape_baser�numpy.lib.index_tricksr�numpy.matrixlib.defmatrixr�__all__�partial�array_function_dispatchr=rAr!rGr"rKrr_rrbrrrkrrwrrr�rr�rr�rrrr�r r�rr�rr;r;r;r<�<module>sz �
914  t
915  U
916  
917  V
918  \
919  .
920  >
921  	
922  7M
923  E
924  0
925  +

926  q