?????????? ????????? - ??????????????? - /usr/lib64/python3.9/site-packages/numpy/lib/__pycache__/shape_base.cpython-39.opt-1.pyc
???????
a z[ycc� � @ s* d dl Z d dlm mZ d dlmZmZmZmZm Z m Z d dlmZm Z d dlmZ d dlmZ d dlmZmZ d dlmZ d dlmZ d d lmZ d d lmZ g d�Ze jejdd �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��Z0dLd2d3�Z1ee1�dMd4d5��Z2d6d7� Z3ee3�d8d9� �Z4ee3�d:d;� �Z5ee3�d<d=� �Z6d>d?� Z7d@dA� Z8dBdC� Z9ee9�dDdE� �Z:dFdG� Z;ee;�dHdI� �Z<dS )N� N)�asarray�zeros�outer�concatenate�array� asanyarray)�reshape� transpose)�normalize_axis_index)� overrides)�vstack� 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_axisZnumpy)�modulec C s� t �|jt j�std��t| �|jkr.td��d|j }tt |��d g tt |d |j�� }g }t || �D ]R\}}|d u r�|�|� ql|d |� d ||d d � }|�t �|�� |�� qlt|�S )Nz"`indices` must be an integer arrayz;`indices` and `arr` must have the same number of dimensions�� r% )���)�_nxZ issubdtype�dtypeZinteger� IndexError�len�ndim� ValueError�list�range�zip�appendZaranger �tuple) � arr_shape�indices�axisZ shape_onesZ dest_dimsZfancy_indexZdim�nZ ind_shape� r6 �:/usr/lib64/python3.9/site-packages/numpy/lib/shape_base.py�_make_along_axis_idx s � & r8 c C s | |fS �Nr6 )�arrr3 r4 r6 r6 r7 �_take_along_axis_dispatcher4 s r; c C s@ |du r| j } t| �f}d}nt|| j�}| j}| t|||� S )aw Take values from the input array by matching 1d index and data slices. This iterates over matching 1d slices oriented along the specified axis in the index and data arrays, and uses the former to look up values in the latter. These slices can be different lengths. Functions returning an index along an axis, like `argsort` and `argpartition`, produce suitable indices for this function. .. versionadded:: 1.15.0 Parameters ---------- arr : ndarray (Ni..., M, Nk...) Source array indices : ndarray (Ni..., J, Nk...) Indices to take along each 1d slice of `arr`. This must match the dimension of arr, but dimensions Ni and Nj only need to broadcast against `arr`. axis : int The axis to take 1d slices along. If axis is None, the input array is treated as if it had first been flattened to 1d, for consistency with `sort` and `argsort`. Returns ------- out: ndarray (Ni..., J, Nk...) The indexed result. Notes ----- This is equivalent to (but faster than) the following use of `ndindex` and `s_`, which sets each of ``ii`` and ``kk`` to a tuple of indices:: Ni, M, Nk = a.shape[:axis], a.shape[axis], a.shape[axis+1:] J = indices.shape[axis] # Need not equal M out = np.empty(Ni + (J,) + Nk) for ii in ndindex(Ni): for kk in ndindex(Nk): a_1d = a [ii + s_[:,] + kk] indices_1d = indices[ii + s_[:,] + kk] out_1d = out [ii + s_[:,] + kk] for j in range(J): out_1d[j] = a_1d[indices_1d[j]] Equivalently, eliminating the inner loop, the last two lines would be:: out_1d[:] = a_1d[indices_1d] See Also -------- take : Take along an axis, using the same indices for every 1d slice put_along_axis : Put values into the destination array by matching 1d index and data slices Examples -------- For this sample array >>> a = np.array([[10, 30, 20], [60, 40, 50]]) We can sort either by using sort directly, or argsort and this function >>> np.sort(a, axis=1) array([[10, 20, 30], [40, 50, 60]]) >>> ai = np.argsort(a, axis=1); ai array([[0, 2, 1], [1, 2, 0]]) >>> np.take_along_axis(a, ai, axis=1) array([[10, 20, 30], [40, 50, 60]]) The same works for max and min, if you expand the dimensions: >>> np.expand_dims(np.max(a, axis=1), axis=1) array([[30], [60]]) >>> ai = np.expand_dims(np.argmax(a, axis=1), axis=1) >>> ai array([[1], [0]]) >>> np.take_along_axis(a, ai, axis=1) array([[30], [60]]) If we want to get the max and min at the same time, we can stack the indices first >>> ai_min = np.expand_dims(np.argmin(a, axis=1), axis=1) >>> ai_max = np.expand_dims(np.argmax(a, axis=1), axis=1) >>> ai = np.concatenate([ai_min, ai_max], axis=1) >>> ai array([[0, 1], [1, 0]]) >>> np.take_along_axis(a, ai, axis=1) array([[10, 30], [40, 60]]) Nr �Zflatr* r r+ �shaper8 )r: r3 r4 r2 r6 r6 r7 r! 8 s i r! c C s | ||fS r9 r6 )r: r3 �valuesr4 r6 r6 r7 �_put_along_axis_dispatcher� s r? c C sD |du r| j } d}t| �f}nt|| j�}| j}|| t|||�<