관리-도구
편집 파일: fromnumeric.cpython-311.pyc
� �܋f5� � �6 � d Z ddlZddlZddlZddlZddlmZ ddlm Z ddlmZ ddlmZ dd lmZ dd l mZmZmZmZ ddlmZ ej Zg d�Zej ZeZ ej ej d �� � Zd� Zd� Zd� Z dtd�Z! ee!� � dud�� � Z"dvd�Z# ee#� � dwd�� � Z$dxd�Z% ee%� � dyd�� � Z&dvd�Z' ee'� � dvd�� � Z(dvd�Z) ee)� � dzd�� � Z*d� Z+ ee+� � d� � � Z,dvd �Z- ee-� � dvd!�� � Z.dtd"�Z/ ee/� � d{d%�� � Z0dtd&�Z1 ee1� � d{d'�� � Z2dtd(�Z3 ee3� � d|d)�� � Z4dtd*�Z5 ee5� � d|d+�� � Z6dxej7 d,�d-�Z8 ee8� � dxej7 d,�d.�� � Z9dxej7 d,�d/�Z: ee:� � dxej7 d,�d0�� � Z;dxd1�Z< ee<� � d}d3�� � Z=d4� Z> ee>� � d5� � � Z?dvd6�Z@ ee@� � dvd7�� � ZAdtd8�ZB eeB� � d~d9�� � ZC dd:�ZD eeD� � d�d;�� � ZEdvd<�ZF eeF� � dwd=�� � ZGd>� ZH eeH� � d?� � � ZId@� ZJ eeJ� � dA� � � ZKdxdB�ZL eeL� � dxdC�� � ZMdvdD�ZN eeN� � dvdE�� � ZO d�dF�ZP eeP� � dddej7 ej7 ej7 fdG�� � Zdtej7 dH�dI�ZQ eeQ� � ddej7 fej7 dH�dJ�� � ZRdtddH�dK�ZS eeS� � ddej7 fej7 dH�dL�� � ZTdtdM�ZU eeU� � dtdN�� � ZVdtdO�ZW eeW� � ddej7 fdP�� � ZX ddQ�ZY eeY� � ed � � ddej7 ej7 ej7 fdR�� � � � ZZ eeY� � ddej7 ej7 ej7 fdS�� � Z[ ddT�Z\ ee\� � ddej7 ej7 ej7 fdU�� � Z] ee\� � ddej7 ej7 ej7 fdV�� � Z^ d�dW�Z_ ee_� � dddej7 ej7 ej7 fdX�� � Z`dtdY�Za eea� � dtdZ�� � Zbd[� Zc eec� � d\� � � Zddvd]�Ze eee� � dvd^�� � Zfdxd_�Zg eeg� � d�d`�� � Zh eeg� � d�da�� � Zid�ddH�db�Zj eej� � dddej7 fej7 dH�dc�� � Zk dddH�dd�Zl eel� � ddddej7 fej7 dH�de�� � Zm dddH�df�Zn een� � ddddej7 fej7 dH�dg�� � Zodxdh�Zp eep� � d�di�� � Zq d�dj�Zr eerdk�l� � dm� � � Zsdtdn�Zt eetdk�l� � do� � � Zudtej7 dH�dp�Zv eevdk�l� � dq� � � ZwdtddH�dr�Zx eexdk�l� � ds� � � ZydS )�zCModule containing non-deprecated functions borrowed from Numeric. � N� )� set_module� )� multiarray)� overrides)�umath)�numerictypes)�asarray�array� asanyarray�concatenate)�_methods).�all�alltrue�amax�amin�any�argmax�argmin�argpartition�argsort�around�choose�clip�compress�cumprod� cumproduct�cumsum�diagonal�mean�max�min�ndim�nonzero� partition�prod�product�ptp�put�ravel�repeat�reshape�resize�round�round_�searchsorted�shape�size�sometrue�sort�squeeze�std�sum�swapaxes�take�trace� transpose�var�numpy)�modulec �� � | j }n# t $ r d }Y nw xY w t t | � � |� � |i |��}|r4t |t j � � st |� � } ||� � }|S �N)�__array_wrap__�AttributeError�getattrr � isinstance�mu�ndarray)�obj�method�args�kwds�wrap�results �M/opt/cloudlinux/venv/lib64/python3.11/site-packages/numpy/core/fromnumeric.py�_wrapitrN ( s� � ���!����� � � ��������� *�W�W�S�\�\�6� *� *�D� 9�D� 9� 9�F�� ��&�"�*�-�-� %��V�_�_�F���f�����Ms � ��c � � t | |d � � }|�t | |g|�R i |��S ||i |��S # t $ r t | |g|�R i |��cY S w xY wr@ )rC rN � TypeError)rG rH rI rJ �bounds rM � _wrapfuncrR 5 s� � ��C���&�&�E��}��s�F�2�T�2�2�2�T�2�2�2� 3��u�d�#�d�#�#�#��� 3� 3� 3� �s�F�2�T�2�2�2�T�2�2�2�2�2�3���s �. �A�Ac � � d� |� � � D � � }t | � � t j ur: t | |� � }|� |d|||d�|��S |d||d�|��S # t $ r Y nw xY w |j | |||fi |��S )Nc �6 � i | ]\ }}|t j u�||��S � )�np�_NoValue)�.0�k�vs rM � <dictcomp>z"_wrapreduction.<locals>.<dictcomp>H s4 � � +� +� +�4�1�a��b�k�)�)� �Q�)�)�)� ��axis�dtype�out�r^ r` rU )�items�typerE rF rC rB �reduce) rG �ufuncrH r^ r_ r` �kwargs� passkwargs� reductions rM �_wrapreductionri G s� � �+� +�6�<�<�>�>� +� +� +�J� �C�y�y�� �"�"� C���V�,�,�I� � � �y�O�d�%�S�O�O�J�O�O�O� �y�B�d��B�B�z�B�B�B�� � � � ��D� ���� �5�<��T�5�#�<�<��<�<�<s �A$ �$ A1�0A1c � � | |fS r@ rU ��a�indicesr^ r` �modes rM �_take_dispatcherro [ � � � �s�8�Or\ �raisec �, � t | d||||�� � S )ac Take elements from an array along an axis. When axis is not None, this function does the same thing as "fancy" indexing (indexing arrays using arrays); however, it can be easier to use if you need elements along a given axis. A call such as ``np.take(arr, indices, axis=3)`` is equivalent to ``arr[:,:,:,indices,...]``. Explained without fancy indexing, this is equivalent to the following use of `ndindex`, which sets each of ``ii``, ``jj``, and ``kk`` to a tuple of indices:: Ni, Nk = a.shape[:axis], a.shape[axis+1:] Nj = indices.shape for ii in ndindex(Ni): for jj in ndindex(Nj): for kk in ndindex(Nk): out[ii + jj + kk] = a[ii + (indices[jj],) + kk] Parameters ---------- a : array_like (Ni..., M, Nk...) The source array. indices : array_like (Nj...) The indices of the values to extract. .. versionadded:: 1.8.0 Also allow scalars for indices. axis : int, optional The axis over which to select values. By default, the flattened input array is used. out : ndarray, optional (Ni..., Nj..., Nk...) If provided, the result will be placed in this array. It should be of the appropriate shape and dtype. Note that `out` is always buffered if `mode='raise'`; use other modes for better performance. mode : {'raise', 'wrap', 'clip'}, optional Specifies how out-of-bounds indices will behave. * 'raise' -- raise an error (default) * 'wrap' -- wrap around * 'clip' -- clip to the range 'clip' mode means that all indices that are too large are replaced by the index that addresses the last element along that axis. Note that this disables indexing with negative numbers. Returns ------- out : ndarray (Ni..., Nj..., Nk...) The returned array has the same type as `a`. See Also -------- compress : Take elements using a boolean mask ndarray.take : equivalent method take_along_axis : Take elements by matching the array and the index arrays Notes ----- By eliminating the inner loop in the description above, and using `s_` to build simple slice objects, `take` can be expressed in terms of applying fancy indexing to each 1-d slice:: Ni, Nk = a.shape[:axis], a.shape[axis+1:] for ii in ndindex(Ni): for kk in ndindex(Nj): out[ii + s_[...,] + kk] = a[ii + s_[:,] + kk][indices] For this reason, it is equivalent to (but faster than) the following use of `apply_along_axis`:: out = np.apply_along_axis(lambda a_1d: a_1d[indices], axis, a) Examples -------- >>> a = [4, 3, 5, 7, 6, 8] >>> indices = [0, 1, 4] >>> np.take(a, indices) array([4, 3, 6]) In this example if `a` is an ndarray, "fancy" indexing can be used. >>> a = np.array(a) >>> a[indices] array([4, 3, 6]) If `indices` is not one dimensional, the output also has these dimensions. >>> np.take(a, [[0, 1], [2, 3]]) array([[4, 3], [5, 7]]) r9 )r^ r` rn �rR rk s rM r9 r9 _ s � �B �Q���d��$�G�G�G�Gr\ c � � | fS r@ rU �rl �newshape�orders rM �_reshape_dispatcherrx � � � � �4�Kr\ �Cc �( � t | d||�� � S )a� Gives a new shape to an array without changing its data. Parameters ---------- a : array_like Array to be reshaped. newshape : int or tuple of ints The new shape should be compatible with the original shape. If an integer, then the result will be a 1-D array of that length. One shape dimension can be -1. In this case, the value is inferred from the length of the array and remaining dimensions. order : {'C', 'F', 'A'}, optional Read the elements of `a` using this index order, and place the elements into the reshaped array using this index order. 'C' means to read / write the elements using C-like index order, with the last axis index changing fastest, back to the first axis index changing slowest. 'F' means to read / write the elements using Fortran-like index order, with the first index changing fastest, and the last index changing slowest. Note that the 'C' and 'F' options take no account of the memory layout of the underlying array, and only refer to the order of indexing. 'A' means to read / write the elements in Fortran-like index order if `a` is Fortran *contiguous* in memory, C-like order otherwise. Returns ------- reshaped_array : ndarray This will be a new view object if possible; otherwise, it will be a copy. Note there is no guarantee of the *memory layout* (C- or Fortran- contiguous) of the returned array. See Also -------- ndarray.reshape : Equivalent method. Notes ----- It is not always possible to change the shape of an array without copying the data. The `order` keyword gives the index ordering both for *fetching* the values from `a`, and then *placing* the values into the output array. For example, let's say you have an array: >>> a = np.arange(6).reshape((3, 2)) >>> a array([[0, 1], [2, 3], [4, 5]]) You can think of reshaping as first raveling the array (using the given index order), then inserting the elements from the raveled array into the new array using the same kind of index ordering as was used for the raveling. >>> np.reshape(a, (2, 3)) # C-like index ordering array([[0, 1, 2], [3, 4, 5]]) >>> np.reshape(np.ravel(a), (2, 3)) # equivalent to C ravel then C reshape array([[0, 1, 2], [3, 4, 5]]) >>> np.reshape(a, (2, 3), order='F') # Fortran-like index ordering array([[0, 4, 3], [2, 1, 5]]) >>> np.reshape(np.ravel(a, order='F'), (2, 3), order='F') array([[0, 4, 3], [2, 1, 5]]) Examples -------- >>> a = np.array([[1,2,3], [4,5,6]]) >>> np.reshape(a, 6) array([1, 2, 3, 4, 5, 6]) >>> np.reshape(a, 6, order='F') array([1, 4, 2, 5, 3, 6]) >>> np.reshape(a, (3,-1)) # the unspecified value is inferred to be 2 array([[1, 2], [3, 4], [5, 6]]) r, �rw rs ru s rM r, r, � s � �j �Q� �8�5�9�9�9�9r\ c # �* K � | V � |E d {V �� |V � d S r@ rU �rl �choicesr` rn s rM �_choose_dispatcherr� s4 � � � � �G�G�G��������� �I�I�I�I�Ir\ c �* � t | d|||�� � S )a@ Construct an array from an index array and a list of arrays to choose from. First of all, if confused or uncertain, definitely look at the Examples - in its full generality, this function is less simple than it might seem from the following code description (below ndi = `numpy.lib.index_tricks`): ``np.choose(a,c) == np.array([c[a[I]][I] for I in ndi.ndindex(a.shape)])``. But this omits some subtleties. Here is a fully general summary: Given an "index" array (`a`) of integers and a sequence of ``n`` arrays (`choices`), `a` and each choice array are first broadcast, as necessary, to arrays of a common shape; calling these *Ba* and *Bchoices[i], i = 0,...,n-1* we have that, necessarily, ``Ba.shape == Bchoices[i].shape`` for each ``i``. Then, a new array with shape ``Ba.shape`` is created as follows: * if ``mode='raise'`` (the default), then, first of all, each element of ``a`` (and thus ``Ba``) must be in the range ``[0, n-1]``; now, suppose that ``i`` (in that range) is the value at the ``(j0, j1, ..., jm)`` position in ``Ba`` - then the value at the same position in the new array is the value in ``Bchoices[i]`` at that same position; * if ``mode='wrap'``, values in `a` (and thus `Ba`) may be any (signed) integer; modular arithmetic is used to map integers outside the range `[0, n-1]` back into that range; and then the new array is constructed as above; * if ``mode='clip'``, values in `a` (and thus ``Ba``) may be any (signed) integer; negative integers are mapped to 0; values greater than ``n-1`` are mapped to ``n-1``; and then the new array is constructed as above. Parameters ---------- a : int array This array must contain integers in ``[0, n-1]``, where ``n`` is the number of choices, unless ``mode=wrap`` or ``mode=clip``, in which cases any integers are permissible. choices : sequence of arrays Choice arrays. `a` and all of the choices must be broadcastable to the same shape. If `choices` is itself an array (not recommended), then its outermost dimension (i.e., the one corresponding to ``choices.shape[0]``) is taken as defining the "sequence". out : array, optional If provided, the result will be inserted into this array. It should be of the appropriate shape and dtype. Note that `out` is always buffered if ``mode='raise'``; use other modes for better performance. mode : {'raise' (default), 'wrap', 'clip'}, optional Specifies how indices outside ``[0, n-1]`` will be treated: * 'raise' : an exception is raised * 'wrap' : value becomes value mod ``n`` * 'clip' : values < 0 are mapped to 0, values > n-1 are mapped to n-1 Returns ------- merged_array : array The merged result. Raises ------ ValueError: shape mismatch If `a` and each choice array are not all broadcastable to the same shape. See Also -------- ndarray.choose : equivalent method numpy.take_along_axis : Preferable if `choices` is an array Notes ----- To reduce the chance of misinterpretation, even though the following "abuse" is nominally supported, `choices` should neither be, nor be thought of as, a single array, i.e., the outermost sequence-like container should be either a list or a tuple. Examples -------- >>> choices = [[0, 1, 2, 3], [10, 11, 12, 13], ... [20, 21, 22, 23], [30, 31, 32, 33]] >>> np.choose([2, 3, 1, 0], choices ... # the first element of the result will be the first element of the ... # third (2+1) "array" in choices, namely, 20; the second element ... # will be the second element of the fourth (3+1) choice array, i.e., ... # 31, etc. ... ) array([20, 31, 12, 3]) >>> np.choose([2, 4, 1, 0], choices, mode='clip') # 4 goes to 3 (4-1) array([20, 31, 12, 3]) >>> # because there are 4 choice arrays >>> np.choose([2, 4, 1, 0], choices, mode='wrap') # 4 goes to (4 mod 4) array([20, 1, 12, 3]) >>> # i.e., 0 A couple examples illustrating how choose broadcasts: >>> a = [[1, 0, 1], [0, 1, 0], [1, 0, 1]] >>> choices = [-10, 10] >>> np.choose(a, choices) array([[ 10, -10, 10], [-10, 10, -10], [ 10, -10, 10]]) >>> # With thanks to Anne Archibald >>> a = np.array([0, 1]).reshape((2,1,1)) >>> c1 = np.array([1, 2, 3]).reshape((1,3,1)) >>> c2 = np.array([-1, -2, -3, -4, -5]).reshape((1,1,5)) >>> np.choose(a, (c1, c2)) # result is 2x3x5, res[0,:,:]=c1, res[1,:,:]=c2 array([[[ 1, 1, 1, 1, 1], [ 2, 2, 2, 2, 2], [ 3, 3, 3, 3, 3]], [[-1, -2, -3, -4, -5], [-1, -2, -3, -4, -5], [-1, -2, -3, -4, -5]]]) r )r` rn rs r~ s rM r r & s � �t �Q��'�s��>�>�>�>r\ c � � | fS r@ rU �rl �repeatsr^ s rM �_repeat_dispatcherr� � ry r\ c �( � t | d||�� � S )a Repeat each element of an array after themselves Parameters ---------- a : array_like Input array. repeats : int or array of ints The number of repetitions for each element. `repeats` is broadcasted to fit the shape of the given axis. axis : int, optional The axis along which to repeat values. By default, use the flattened input array, and return a flat output array. Returns ------- repeated_array : ndarray Output array which has the same shape as `a`, except along the given axis. See Also -------- tile : Tile an array. unique : Find the unique elements of an array. Examples -------- >>> np.repeat(3, 4) array([3, 3, 3, 3]) >>> x = np.array([[1,2],[3,4]]) >>> np.repeat(x, 2) array([1, 1, 2, 2, 3, 3, 4, 4]) >>> np.repeat(x, 3, axis=1) array([[1, 1, 1, 2, 2, 2], [3, 3, 3, 4, 4, 4]]) >>> np.repeat(x, [1, 2], axis=0) array([[1, 2], [3, 4], [3, 4]]) r+ �r^ rs r� s rM r+ r+ � s � �V �Q��'��5�5�5�5r\ c � � | ||fS r@ rU )rl �indrZ rn s rM �_put_dispatcherr� � s � � �s�A�;�r\ c � � | j }nH# t $ r;}t d� t | � � j �� � � � |�d}~ww xY w ||||�� � S )aN Replaces specified elements of an array with given values. The indexing works on the flattened target array. `put` is roughly equivalent to: :: a.flat[ind] = v Parameters ---------- a : ndarray Target array. ind : array_like Target indices, interpreted as integers. v : array_like Values to place in `a` at target indices. If `v` is shorter than `ind` it will be repeated as necessary. mode : {'raise', 'wrap', 'clip'}, optional Specifies how out-of-bounds indices will behave. * 'raise' -- raise an error (default) * 'wrap' -- wrap around * 'clip' -- clip to the range 'clip' mode means that all indices that are too large are replaced by the index that addresses the last element along that axis. Note that this disables indexing with negative numbers. In 'raise' mode, if an exception occurs the target array may still be modified. See Also -------- putmask, place put_along_axis : Put elements by matching the array and the index arrays Examples -------- >>> a = np.arange(5) >>> np.put(a, [0, 2], [-44, -55]) >>> a array([-44, 1, -55, 3, 4]) >>> a = np.arange(5) >>> np.put(a, 22, -5, mode='clip') >>> a array([ 0, 1, 2, 3, -5]) z,argument 1 must be numpy.ndarray, not {name})�nameN)rn )r) rB rP �formatrc �__name__)rl r� rZ rn r) �es rM r) r) � s� � �fK��e����� K� K� K�� %�%+�V��a���1A�V�%B�%B�D� D�IJ� K�����K���� �3�s�A�D�!�!�!�!s � � A�6A � Ac � � | fS r@ rU �rl �axis1�axis2s rM �_swapaxes_dispatcherr� ry r\ c �&