
    G/Ph1~                     P   d dl Z d dlZd dlZd dlZd dlZddlmZ d dlm	c m
Z d dlmZmZ d dlmZ d dlmZ d dlmZmZ d dlmZmZ d dlmZ d d	lmZ  e j        ej        d
          Zg dZd Z ee          d             Z  G d d          Z! G d de!          Z" e"            Z# G d de!          Z$ e$            Z% G d d          Z& G d de&          Z' e'            Z( G d de&          Z) e)            Z* ed
           G d d                      Z+ ed
           G d d                      Z, G d d           Z- e-d!"          Z. e-d#"          Z/d)d$Z0 ee0          d*d%            Z1 ed
          d+d&            Z2d' Z3 ee3          d(             Z4dS ),    N   )
set_module)
ScalarTypearray)
issubdtype)ravel_multi_indexunravel_index)	overrideslinspace)
as_strided)diffnumpy)module)r   r	   mgridogridr_c_s_	index_expix_ndenumeratendindexfill_diagonaldiag_indicesdiag_indices_fromc                      | S N )argss    \/var/www/html/test/jupyter/venv/lib/python3.11/site-packages/numpy/lib/_index_tricks_impl.py_ix__dispatcherr!      s    K    c                  >   g }t          |           }t          |           D ]\  }}t          |t          j                  s>t          j        |          }|j        dk    r|                    t          j	                  }|j
        dk    rt          d          t          |j        t          j                  r|                                \  }|                    d|z  |j        fz   d||z
  dz
  z  z             }|                    |           t%          |          S )aP  
    Construct an open mesh from multiple sequences.

    This function takes N 1-D sequences and returns N outputs with N
    dimensions each, such that the shape is 1 in all but one dimension
    and the dimension with the non-unit shape value cycles through all
    N dimensions.

    Using `ix_` one can quickly construct index arrays that will index
    the cross product. ``a[np.ix_([1,3],[2,5])]`` returns the array
    ``[[a[1,2] a[1,5]], [a[3,2] a[3,5]]]``.

    Parameters
    ----------
    args : 1-D sequences
        Each sequence should be of integer or boolean type.
        Boolean sequences will be interpreted as boolean masks for the
        corresponding dimension (equivalent to passing in
        ``np.nonzero(boolean_sequence)``).

    Returns
    -------
    out : tuple of ndarrays
        N arrays with N dimensions each, with N the number of input
        sequences. Together these arrays form an open mesh.

    See Also
    --------
    ogrid, mgrid, meshgrid

    Examples
    --------
    >>> import numpy as np
    >>> a = np.arange(10).reshape(2, 5)
    >>> a
    array([[0, 1, 2, 3, 4],
           [5, 6, 7, 8, 9]])
    >>> ixgrid = np.ix_([0, 1], [2, 4])
    >>> ixgrid
    (array([[0],
           [1]]), array([[2, 4]]))
    >>> ixgrid[0].shape, ixgrid[1].shape
    ((2, 1), (1, 2))
    >>> a[ixgrid]
    array([[2, 4],
           [7, 9]])

    >>> ixgrid = np.ix_([True, True], [2, 4])
    >>> a[ixgrid]
    array([[2, 4],
           [7, 9]])
    >>> ixgrid = np.ix_([True, True], [False, False, True, False, True])
    >>> a[ixgrid]
    array([[2, 4],
           [7, 9]])

    r      z!Cross index must be 1 dimensional)r$   )len	enumerate
isinstance_nxndarraynpasarraysizeastypeintpndim
ValueErrorr   dtypeboolnonzeroreshapeappendtuple)r   outndknews        r    r   r   "   s    v C	TBD//  3#s{++ 	+*S//Cx1}}jj**8q==@AAAci** 	!;;==DCkk$q&CH;.r!tAv>??

3::r"   c                   $    e Zd ZdZdZddZd ZdS )nd_grida  
    Construct a multi-dimensional "meshgrid".

    ``grid = nd_grid()`` creates an instance which will return a mesh-grid
    when indexed.  The dimension and number of the output arrays are equal
    to the number of indexing dimensions.  If the step length is not a
    complex number, then the stop is not inclusive.

    However, if the step length is a **complex number** (e.g. 5j), then the
    integer part of its magnitude is interpreted as specifying the
    number of points to create between the start and stop values, where
    the stop value **is inclusive**.

    If instantiated with an argument of ``sparse=True``, the mesh-grid is
    open (or not fleshed out) so that only one-dimension of each returned
    argument is greater than 1.

    Parameters
    ----------
    sparse : bool, optional
        Whether the grid is sparse or not. Default is False.

    Notes
    -----
    Two instances of `nd_grid` are made available in the NumPy namespace,
    `mgrid` and `ogrid`, approximately defined as::

        mgrid = nd_grid(sparse=False)
        ogrid = nd_grid(sparse=True)

    Users should use these pre-defined instances instead of using `nd_grid`
    directly.
    sparseFc                     || _         d S r   r=   )selfr>   s     r    __init__znd_grid.__init__   s    r"   c           
         	 g }dg}t          t          |                    D ]}||         j        }||         j        }||         j        }|d}|d}t          |t          j        t          f          r2t          |          }|
                    t          |                     n=|
                    t          t          j        ||z
  |dz  z                                 ||||gz  }t          j        | }| j        r,d t!          ||ft          |          z            D             }	nt          j        ||          }	t%          |          D ]\  }}
|
j        }|
j        }|d}|d}t          |t          j        t          f          r?t          t          |                    }|dk    r|
j        |z
  t'          |dz
            z  }|	|         |z  |z   |	|<   | j        rt          j        gt          |          z  }t          t          |                    D ]B}t+          d d           ||<   |	|         t-          |                   |	|<   t          j        ||<   Ct-          |	          S |	S # t.          t0          f$ r |j        }|j        }|j        }|d}t          |t          j        t          f          ryt          |          }t          |          x}}|dk    r|j        |z
  t'          |dz
            z  }t          j        |||          }t          j        d|d|          |z  |z   cY S t          j        |||          cY S w xY w)Nr   r$   g      ?c                 @    g | ]\  }}t          j        ||           S )r1   )r(   arange).0_x_ts      r    
<listcomp>z'nd_grid.__getitem__.<locals>.<listcomp>   sA     A A A "b j2... A A Ar"   rD   )ranger%   stepstartstopr'   r(   complexfloatingcomplexabsr5   intmathceilresult_typer>   zipindicesr&   floatnewaxisslicer6   
IndexError	TypeErrorrE   )r@   keyr,   num_listr9   rK   rL   rM   typnnkkslobj
step_floatlengths                 r    __getitem__znd_grid.__getitem__   sl   =	5D sH3s88__ 0 01v{A1v{=E<DdS%8'$BCC Et99DKKD		****KKDIte|S&ABBCCE E EUD$///8,C{ ,A A$'sfSYY.>$?$?A A A [s++"3 + +2w=E<DdS%8'$BCC Cs4yy>>Dqyy "%5??BAtE)1{ !c$ii/s4yy)) + +A$T400E!HqE%,,/BqE"{E!HHRyy II& 	5 	5 	58D8DIE}$!4g >?? 	5 YY
 #J/v199HUNE$q&MM9DoeT:>>z!VQc:::4?%GGGGz%t44444	5s   I.I3 1I3 3CM7MMNF__name__
__module____qualname____doc__	__slots__rA   rd   r   r"   r    r<   r<   n   sI           B I   >5 >5 >5 >5 >5r"   r<   c                   &     e Zd ZdZdZ fdZ xZS )
MGridClassaS  
    An instance which returns a dense multi-dimensional "meshgrid".

    An instance which returns a dense (or fleshed out) mesh-grid
    when indexed, so that each returned argument has the same shape.
    The dimensions and number of the output arrays are equal to the
    number of indexing dimensions.  If the step length is not a complex
    number, then the stop is not inclusive.

    However, if the step length is a **complex number** (e.g. 5j), then
    the integer part of its magnitude is interpreted as specifying the
    number of points to create between the start and stop values, where
    the stop value **is inclusive**.

    Returns
    -------
    mesh-grid : ndarray
        A single array, containing a set of `ndarray`\ s all of the same
        dimensions. stacked along the first axis.

    See Also
    --------
    ogrid : like `mgrid` but returns open (not fleshed out) mesh grids
    meshgrid: return coordinate matrices from coordinate vectors
    r_ : array concatenator
    :ref:`how-to-partition`

    Examples
    --------
    >>> import numpy as np
    >>> np.mgrid[0:5, 0:5]
    array([[[0, 0, 0, 0, 0],
            [1, 1, 1, 1, 1],
            [2, 2, 2, 2, 2],
            [3, 3, 3, 3, 3],
            [4, 4, 4, 4, 4]],
           [[0, 1, 2, 3, 4],
            [0, 1, 2, 3, 4],
            [0, 1, 2, 3, 4],
            [0, 1, 2, 3, 4],
            [0, 1, 2, 3, 4]]])
    >>> np.mgrid[-1:1:5j]
    array([-1. , -0.5,  0. ,  0.5,  1. ])

    >>> np.mgrid[0:4].shape
    (4,)
    >>> np.mgrid[0:4, 0:5].shape
    (2, 4, 5)
    >>> np.mgrid[0:4, 0:5, 0:6].shape
    (3, 4, 5, 6)

    r   c                 L    t                                          d           d S )NFr=   superrA   r@   	__class__s    r    rA   zMGridClass.__init__  s$    &&&&&r"   rg   rh   ri   rj   rk   rA   __classcell__rr   s   @r    rm   rm      sJ        3 3h I' ' ' ' ' ' ' ' 'r"   rm   c                   &     e Zd ZdZdZ fdZ xZS )
OGridClassaw  
    An instance which returns an open multi-dimensional "meshgrid".

    An instance which returns an open (i.e. not fleshed out) mesh-grid
    when indexed, so that only one dimension of each returned array is
    greater than 1.  The dimension and number of the output arrays are
    equal to the number of indexing dimensions.  If the step length is
    not a complex number, then the stop is not inclusive.

    However, if the step length is a **complex number** (e.g. 5j), then
    the integer part of its magnitude is interpreted as specifying the
    number of points to create between the start and stop values, where
    the stop value **is inclusive**.

    Returns
    -------
    mesh-grid : ndarray or tuple of ndarrays
        If the input is a single slice, returns an array.
        If the input is multiple slices, returns a tuple of arrays, with
        only one dimension not equal to 1.

    See Also
    --------
    mgrid : like `ogrid` but returns dense (or fleshed out) mesh grids
    meshgrid: return coordinate matrices from coordinate vectors
    r_ : array concatenator
    :ref:`how-to-partition`

    Examples
    --------
    >>> from numpy import ogrid
    >>> ogrid[-1:1:5j]
    array([-1. , -0.5,  0. ,  0.5,  1. ])
    >>> ogrid[0:5, 0:5]
    (array([[0],
            [1],
            [2],
            [3],
            [4]]),
     array([[0, 1, 2, 3, 4]]))

    r   c                 L    t                                          d           d S )NTr=   ro   rq   s    r    rA   zOGridClass.__init__A  s$    %%%%%r"   rs   ru   s   @r    rw   rw     sJ        ) )T I& & & & & & & & &r"   rw   c                   j    e Zd ZdZdZ eej                  Z eej	                  Z
ddZd Zd	 Zd
S )AxisConcatenatorzv
    Translates slice objects to concatenation along an axis.

    For detailed documentation on usage, see `r_`.
    axismatrixtrans1dndminr   Fr$   c                 >    || _         || _        || _        || _        d S r   r{   )r@   r|   r}   r   r~   s        r    rA   zAxisConcatenator.__init__T  s"    	


r"   c                    t          |t                    r:t          j                    j        }t          j        ||j        |j                  }|S t          |t                    s|f}| j
        }| j        | j        }| j        }g }g }t          |          D ]\  }	}
d}t          |
t                    r|
j        }|
j        }|
j        }|d}|d}t          |t&          j        t*          f          r/t-          t/          |                    }t1          |||          }nt'          j        |||          }dk    r.t5          |d           }|dk    r|                    d|          }nt          |
t                    r|	dk    rt9          d          |
dv r
d	}|
d
k    }d|
v r|
                    d          }	 d |d d         D             \  }t=          |          dk    rt-          |d                   }i# t>          $ r(}t9          d                     |
                    |d }~ww xY w	 t-          |
          }# t8          tB          f$ r}t9          d          |d }~ww xY wtE          |
          tF          v rd	}|
}ntI          j%        |
          }t5          |
d d	          }|dk    rl|k     rf|z
  }|}|dk     r||dz   z  }tM          tO                              }|d |         ||d          z   |||         z   }|(                    |          }|)                    |           |r|)                    |
           |)                    |j*                   t=          |          dk    rt'          j+        | fd|D             }| ,                    t          |          |          }|r+|j%        }| -                    |          }|dk    r	|r|j.        }|S )NFr   r$   )num)copyr   r   z+special directives must be the first entry.)rcTr   ,c                 ,    g | ]}t          |          S r   )rQ   )rF   xs     r    rI   z0AxisConcatenator.__getitem__.<locals>.<listcomp>  s    &?&?&?!s1vv&?&?&?r"   r      zunknown special directive {!r}zunknown special directive)r   subokr   c           	      8    g | ]}t          |d d          S )NT)r   r   r   r1   )r   )rF   objfinal_dtyper   s     r    rI   z0AxisConcatenator.__getitem__.<locals>.<listcomp>  sI     K K K>A #D %[: : : K K Kr"   )r|   )/r'   strsys	_getframef_back	matrixlibbmat	f_globalsf_localsr6   r~   r   r}   r|   r&   rY   rK   rL   rM   r(   rN   rO   rQ   rP   r   rE   r   swapaxesr0   splitr%   	Exceptionformatr[   typer   r*   r/   listrJ   	transposer5   r1   rT   concatenatemakematT)r@   r\   framemymatr~   r}   r|   objsresult_type_objsr9   itemscalarrK   rL   rM   r,   newobjcolvece	item_ndimk2k1defaxesaxesresoldndimr   r   s                              @@r    rd   zAxisConcatenator.__getitem__Z  sf   c3 	MOO*EN3HHEL#u%% 	&C ,
y ~~ >	6 >	6GAtF$&& 64y
y=E<DdS%8'$BCC ;s4yy>>D%eTt<<<FF ZtT::F199"6EBBBF"}}!'W!=!=D#&& %466$ &4 5 5 5:%%!F3;C$;;**S//C!&?&?s2A2w&?&?&?es88q==&)#a&kkG $ ! ! !(<CCDII  !!It99D"I. I I I$%@AAqHIdz))GDMM	t$d%HHHb==Y%6%6*B BAvvb1f"5<<00G"3B3<'"##,6BGD#--d33FKK 6 ''---- ''5555   A%%/+;<KK K K K KEIK K KD uT{{66 	hG,,s##C!|||e
s0   ?H
H4#H//H48I		I/I**I/c                     dS Nr   r   r@   s    r    __len__zAxisConcatenator.__len__  s    qr"   N)r   Fr$   r   )rg   rh   ri   rj   rk   staticmethodr(   r   r   r}   r   rA   rd   r   r   r"   r    rz   rz   H  s         
 7I ,s//Kl9+,,G   c c cJ    r"   rz   c                       e Zd ZdZdZd ZdS )RClassa  
    Translates slice objects to concatenation along the first axis.

    This is a simple way to build up arrays quickly. There are two use cases.

    1. If the index expression contains comma separated arrays, then stack
       them along their first axis.
    2. If the index expression contains slice notation or scalars then create
       a 1-D array with a range indicated by the slice notation.

    If slice notation is used, the syntax ``start:stop:step`` is equivalent
    to ``np.arange(start, stop, step)`` inside of the brackets. However, if
    ``step`` is an imaginary number (i.e. 100j) then its integer portion is
    interpreted as a number-of-points desired and the start and stop are
    inclusive. In other words ``start:stop:stepj`` is interpreted as
    ``np.linspace(start, stop, step, endpoint=1)`` inside of the brackets.
    After expansion of slice notation, all comma separated sequences are
    concatenated together.

    Optional character strings placed as the first element of the index
    expression can be used to change the output. The strings 'r' or 'c' result
    in matrix output. If the result is 1-D and 'r' is specified a 1 x N (row)
    matrix is produced. If the result is 1-D and 'c' is specified, then a N x 1
    (column) matrix is produced. If the result is 2-D then both provide the
    same matrix result.

    A string integer specifies which axis to stack multiple comma separated
    arrays along. A string of two comma-separated integers allows indication
    of the minimum number of dimensions to force each entry into as the
    second integer (the axis to concatenate along is still the first integer).

    A string with three comma-separated integers allows specification of the
    axis to concatenate along, the minimum number of dimensions to force the
    entries to, and which axis should contain the start of the arrays which
    are less than the specified number of dimensions. In other words the third
    integer allows you to specify where the 1's should be placed in the shape
    of the arrays that have their shapes upgraded. By default, they are placed
    in the front of the shape tuple. The third argument allows you to specify
    where the start of the array should be instead. Thus, a third argument of
    '0' would place the 1's at the end of the array shape. Negative integers
    specify where in the new shape tuple the last dimension of upgraded arrays
    should be placed, so the default is '-1'.

    Parameters
    ----------
    Not a function, so takes no parameters


    Returns
    -------
    A concatenated ndarray or matrix.

    See Also
    --------
    concatenate : Join a sequence of arrays along an existing axis.
    c_ : Translates slice objects to concatenation along the second axis.

    Examples
    --------
    >>> import numpy as np
    >>> np.r_[np.array([1,2,3]), 0, 0, np.array([4,5,6])]
    array([1, 2, 3, ..., 4, 5, 6])
    >>> np.r_[-1:1:6j, [0]*3, 5, 6]
    array([-1. , -0.6, -0.2,  0.2,  0.6,  1. ,  0. ,  0. ,  0. ,  5. ,  6. ])

    String integers specify the axis to concatenate along or the minimum
    number of dimensions to force entries into.

    >>> a = np.array([[0, 1, 2], [3, 4, 5]])
    >>> np.r_['-1', a, a] # concatenate along last axis
    array([[0, 1, 2, 0, 1, 2],
           [3, 4, 5, 3, 4, 5]])
    >>> np.r_['0,2', [1,2,3], [4,5,6]] # concatenate along first axis, dim>=2
    array([[1, 2, 3],
           [4, 5, 6]])

    >>> np.r_['0,2,0', [1,2,3], [4,5,6]]
    array([[1],
           [2],
           [3],
           [4],
           [5],
           [6]])
    >>> np.r_['1,2,0', [1,2,3], [4,5,6]]
    array([[1, 4],
           [2, 5],
           [3, 6]])

    Using 'r' or 'c' as a first string argument creates a matrix.

    >>> np.r_['r',[1,2,3], [4,5,6]]
    matrix([[1, 2, 3, 4, 5, 6]])

    r   c                 <    t                               | d           d S r   rz   rA   r   s    r    rA   zRClass.__init__(  s    !!$*****r"   Nrg   rh   ri   rj   rk   rA   r   r"   r    r   r     s7        ] ]| I+ + + + +r"   r   c                       e Zd ZdZdZd ZdS )CClassa  
    Translates slice objects to concatenation along the second axis.

    This is short-hand for ``np.r_['-1,2,0', index expression]``, which is
    useful because of its common occurrence. In particular, arrays will be
    stacked along their last axis after being upgraded to at least 2-D with
    1's post-pended to the shape (column vectors made out of 1-D arrays).

    See Also
    --------
    column_stack : Stack 1-D arrays as columns into a 2-D array.
    r_ : For more detailed documentation.

    Examples
    --------
    >>> import numpy as np
    >>> np.c_[np.array([1,2,3]), np.array([4,5,6])]
    array([[1, 4],
           [2, 5],
           [3, 6]])
    >>> np.c_[np.array([[1,2,3]]), 0, 0, np.array([[4,5,6]])]
    array([[1, 2, 3, ..., 4, 5, 6]])

    r   c                 B    t                               | ddd           d S )Nr   r   r   )r   r~   r   r   s    r    rA   zCClass.__init__J  s%    !!$!Q!?????r"   Nr   r   r"   r    r   r   /  s9         0 I@ @ @ @ @r"   r   c                   $    e Zd ZdZd Zd Zd ZdS )r   a  
    Multidimensional index iterator.

    Return an iterator yielding pairs of array coordinates and values.

    Parameters
    ----------
    arr : ndarray
      Input array.

    See Also
    --------
    ndindex, flatiter

    Examples
    --------
    >>> import numpy as np
    >>> a = np.array([[1, 2], [3, 4]])
    >>> for index, x in np.ndenumerate(a):
    ...     print(index, x)
    (0, 0) 1
    (0, 1) 2
    (1, 0) 3
    (1, 1) 4

    c                 B    t          j        |          j        | _        d S r   )r*   r+   flatiter)r@   arrs     r    rA   zndenumerate.__init__n  s    JsOO(			r"   c                 B    | j         j        t          | j                   fS )a  
        Standard iterator method, returns the index tuple and array value.

        Returns
        -------
        coords : tuple of ints
            The indices of the current iteration.
        val : scalar
            The array element of the current iteration.

        )r   coordsnextr   s    r    __next__zndenumerate.__next__q  s     ydi00r"   c                     | S r   r   r   s    r    __iter__zndenumerate.__iter__      r"   N)rg   rh   ri   rj   rA   r   r   r   r"   r    r   r   Q  sK         6) ) )1 1 1    r"   r   c                   *    e Zd ZdZd Zd Zd Zd ZdS )r   a  
    An N-dimensional iterator object to index arrays.

    Given the shape of an array, an `ndindex` instance iterates over
    the N-dimensional index of the array. At each iteration a tuple
    of indices is returned, the last dimension is iterated over first.

    Parameters
    ----------
    shape : ints, or a single tuple of ints
        The size of each dimension of the array can be passed as
        individual parameters or as the elements of a tuple.

    See Also
    --------
    ndenumerate, flatiter

    Examples
    --------
    >>> import numpy as np

    Dimensions as individual arguments

    >>> for index in np.ndindex(3, 2, 1):
    ...     print(index)
    (0, 0, 0)
    (0, 1, 0)
    (1, 0, 0)
    (1, 1, 0)
    (2, 0, 0)
    (2, 1, 0)

    Same dimensions - but in a tuple ``(3, 2, 1)``

    >>> for index in np.ndindex((3, 2, 1)):
    ...     print(index)
    (0, 0, 0)
    (0, 1, 0)
    (1, 0, 0)
    (1, 1, 0)
    (2, 0, 0)
    (2, 1, 0)

    c                    t          |          dk    r#t          |d         t                    r|d         }t          t	          j        d          |t	          j        |                    }t	          j        |ddgd          | _        d S )Nr$   r   )shapestridesmulti_indexzerosize_okC)flagsorder)	r%   r'   r6   r   r(   zeros
zeros_likenditer_it)r@   r   r   s      r    rA   zndindex.__init__  s    u::??z%(E::?!HEsy||5"~e446 6 6:a}'E$') ) )r"   c                     | S r   r   r   s    r    r   zndindex.__iter__  r   r"   c                 \    t          j        dt          d           t          |            dS )a5  
        Increment the multi-dimensional index by one.

        This method is for backward compatibility only: do not use.

        .. deprecated:: 1.20.0
            This method has been advised against since numpy 1.8.0, but only
            started emitting DeprecationWarning as of this version.
        z=`ndindex.ndincr()` is deprecated, use `next(ndindex)` insteadr   )
stacklevelN)warningswarnDeprecationWarningr   r   s    r    ndincrzndindex.ndincr  s6     	K1	. 	. 	. 	. 	T




r"   c                 B    t          | j                   | j        j        S )z
        Standard iterator method, updates the index and returns the index
        tuple.

        Returns
        -------
        val : tuple of ints
            Returns a tuple containing the indices of the current
            iteration.

        )r   r   r   r   s    r    r   zndindex.__next__  s     	TXx##r"   N)rg   rh   ri   rj   rA   r   r   r   r   r"   r    r   r     s[        + +Z) ) )     $ $ $ $ $r"   r   c                   "    e Zd ZdZdZd Zd ZdS )IndexExpressiona1  
    A nicer way to build up index tuples for arrays.

    .. note::
       Use one of the two predefined instances ``index_exp`` or `s_`
       rather than directly using `IndexExpression`.

    For any index combination, including slicing and axis insertion,
    ``a[indices]`` is the same as ``a[np.index_exp[indices]]`` for any
    array `a`. However, ``np.index_exp[indices]`` can be used anywhere
    in Python code and returns a tuple of slice objects that can be
    used in the construction of complex index expressions.

    Parameters
    ----------
    maketuple : bool
        If True, always returns a tuple.

    See Also
    --------
    s_ : Predefined instance without tuple conversion:
       `s_ = IndexExpression(maketuple=False)`.
       The ``index_exp`` is another predefined instance that
       always returns a tuple:
       `index_exp = IndexExpression(maketuple=True)`.

    Notes
    -----
    You can do all this with :class:`slice` plus a few special objects,
    but there's a lot to remember and this version is simpler because
    it uses the standard array indexing syntax.

    Examples
    --------
    >>> import numpy as np
    >>> np.s_[2::2]
    slice(2, None, 2)
    >>> np.index_exp[2::2]
    (slice(2, None, 2),)

    >>> np.array([0, 1, 2, 3, 4])[np.s_[2::2]]
    array([2, 4])

    	maketuplec                     || _         d S r   r   )r@   r   s     r    rA   zIndexExpression.__init__  s    "r"   c                 D    | j         rt          |t                    s|fS |S r   )r   r'   r6   )r@   r   s     r    rd   zIndexExpression.__getitem__  s)    > 	*T5"9"9 	7NKr"   Nrf   r   r"   r    r   r     sD        + +X I# # #    r"   r   Tr   Fc                     | fS r   r   )avalwraps      r    _fill_diagonal_dispatcherr   +  s	    4Kr"   c                    | j         dk     rt          d          d}| j         dk    r.| j        d         dz   }|s| j        d         | j        d         z  }not          j        t          | j                  dk              st          d          dt          j        | j        dd                                                   z   }|| j        d||<   dS )a  Fill the main diagonal of the given array of any dimensionality.

    For an array `a` with ``a.ndim >= 2``, the diagonal is the list of
    values ``a[i, ..., i]`` with indices ``i`` all identical.  This function
    modifies the input array in-place without returning a value.

    Parameters
    ----------
    a : array, at least 2-D.
      Array whose diagonal is to be filled in-place.
    val : scalar or array_like
      Value(s) to write on the diagonal. If `val` is scalar, the value is
      written along the diagonal. If array-like, the flattened `val` is
      written along the diagonal, repeating if necessary to fill all
      diagonal entries.

    wrap : bool
      For tall matrices in NumPy version up to 1.6.2, the
      diagonal "wrapped" after N columns. You can have this behavior
      with this option. This affects only tall matrices.

    See also
    --------
    diag_indices, diag_indices_from

    Notes
    -----
    .. versionadded:: 1.4.0

    This functionality can be obtained via `diag_indices`, but internally
    this version uses a much faster implementation that never constructs the
    indices and uses simple slicing.

    Examples
    --------
    >>> import numpy as np
    >>> a = np.zeros((3, 3), int)
    >>> np.fill_diagonal(a, 5)
    >>> a
    array([[5, 0, 0],
           [0, 5, 0],
           [0, 0, 5]])

    The same function can operate on a 4-D array:

    >>> a = np.zeros((3, 3, 3, 3), int)
    >>> np.fill_diagonal(a, 4)

    We only show a few blocks for clarity:

    >>> a[0, 0]
    array([[4, 0, 0],
           [0, 0, 0],
           [0, 0, 0]])
    >>> a[1, 1]
    array([[0, 0, 0],
           [0, 4, 0],
           [0, 0, 0]])
    >>> a[2, 2]
    array([[0, 0, 0],
           [0, 0, 0],
           [0, 0, 4]])

    The wrap option affects only tall matrices:

    >>> # tall matrices no wrap
    >>> a = np.zeros((5, 3), int)
    >>> np.fill_diagonal(a, 4)
    >>> a
    array([[4, 0, 0],
           [0, 4, 0],
           [0, 0, 4],
           [0, 0, 0],
           [0, 0, 0]])

    >>> # tall matrices wrap
    >>> a = np.zeros((5, 3), int)
    >>> np.fill_diagonal(a, 4, wrap=True)
    >>> a
    array([[4, 0, 0],
           [0, 4, 0],
           [0, 0, 4],
           [0, 0, 0],
           [4, 0, 0]])

    >>> # wide matrices
    >>> a = np.zeros((3, 5), int)
    >>> np.fill_diagonal(a, 4, wrap=True)
    >>> a
    array([[4, 0, 0, 0, 0],
           [0, 4, 0, 0, 0],
           [0, 0, 4, 0, 0]])

    The anti-diagonal can be filled by reversing the order of elements
    using either `numpy.flipud` or `numpy.fliplr`.

    >>> a = np.zeros((3, 3), int);
    >>> np.fill_diagonal(np.fliplr(a), [1,2,3])  # Horizontal flip
    >>> a
    array([[0, 0, 1],
           [0, 2, 0],
           [3, 0, 0]])
    >>> np.fill_diagonal(np.flipud(a), [1,2,3])  # Vertical flip
    >>> a
    array([[0, 0, 3],
           [0, 2, 0],
           [1, 0, 0]])

    Note that the order in which the diagonal is filled varies depending
    on the flip function.
    r   zarray must be at least 2-dNr$   r   /All dimensions of input must be of equal lengthr   )	r/   r0   r   r*   allr   cumprodsumr   )r   r   r   endrK   s        r    r   r   /  s    b 	vzz5666
Cv{{ wqzA~ 	*'!*qwqz)C vd17mmq()) 	PNOOOBJqwss|,,11333 AF9C9r"   c                 6    t          j        |           }|f|z  S )aD  
    Return the indices to access the main diagonal of an array.

    This returns a tuple of indices that can be used to access the main
    diagonal of an array `a` with ``a.ndim >= 2`` dimensions and shape
    (n, n, ..., n). For ``a.ndim = 2`` this is the usual diagonal, for
    ``a.ndim > 2`` this is the set of indices to access ``a[i, i, ..., i]``
    for ``i = [0..n-1]``.

    Parameters
    ----------
    n : int
      The size, along each dimension, of the arrays for which the returned
      indices can be used.

    ndim : int, optional
      The number of dimensions.

    See Also
    --------
    diag_indices_from

    Notes
    -----
    .. versionadded:: 1.4.0

    Examples
    --------
    >>> import numpy as np

    Create a set of indices to access the diagonal of a (4, 4) array:

    >>> di = np.diag_indices(4)
    >>> di
    (array([0, 1, 2, 3]), array([0, 1, 2, 3]))
    >>> a = np.arange(16).reshape(4, 4)
    >>> a
    array([[ 0,  1,  2,  3],
           [ 4,  5,  6,  7],
           [ 8,  9, 10, 11],
           [12, 13, 14, 15]])
    >>> a[di] = 100
    >>> a
    array([[100,   1,   2,   3],
           [  4, 100,   6,   7],
           [  8,   9, 100,  11],
           [ 12,  13,  14, 100]])

    Now, we create indices to manipulate a 3-D array:

    >>> d3 = np.diag_indices(2, 3)
    >>> d3
    (array([0, 1]), array([0, 1]), array([0, 1]))

    And use it to set the diagonal of an array of zeros to 1:

    >>> a = np.zeros((2, 2, 2), dtype=int)
    >>> a[d3] = 1
    >>> a
    array([[[1, 0],
            [0, 0]],
           [[0, 0],
            [0, 1]]])

    )r*   rE   )nr/   idxs      r    r   r     s    F )A,,C6D=r"   c                     | fS r   r   r   s    r    _diag_indices_fromr     s	    6Mr"   c                     | j         dk    st          d          t          j        t	          | j                  dk              st          d          t          | j        d         | j                   S )aV  
    Return the indices to access the main diagonal of an n-dimensional array.

    See `diag_indices` for full details.

    Parameters
    ----------
    arr : array, at least 2-D

    See Also
    --------
    diag_indices

    Notes
    -----
    .. versionadded:: 1.4.0

    Examples
    --------
    >>> import numpy as np

    Create a 4 by 4 array.

    >>> a = np.arange(16).reshape(4, 4)
    >>> a
    array([[ 0,  1,  2,  3],
           [ 4,  5,  6,  7],
           [ 8,  9, 10, 11],
           [12, 13, 14, 15]])

    Get the indices of the diagonal elements.

    >>> di = np.diag_indices_from(a)
    >>> di
    (array([0, 1, 2, 3]), array([0, 1, 2, 3]))

    >>> a[di]
    array([ 0,  5, 10, 15])

    This is simply syntactic sugar for diag_indices.

    >>> np.diag_indices(a.shape[0])
    (array([0, 1, 2, 3]), array([0, 1, 2, 3]))

    r   z input array must be at least 2-dr   r   )r/   r0   r*   r   r   r   r   r   s    r    r   r      sh    ` 8q==;<<< 6$sy//Q&'' LJKKK	!ch///r"   r   re   )r   )5	functoolsr   rR   r   r   r*   _utilsr   numpy._core.numeric_corenumericr(   r   r   numpy._core.numerictypesr   numpy.matrixlibr   numpy._core.multiarrayr   r	   numpy._corer
   r   numpy.lib.stride_tricksr   numpy.lib._function_base_implr   partialarray_function_dispatch__all__r!   r   r<   rm   r   rw   r   rz   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r"   r    <module>r     sE       



             ! ! ! ! ! ! ! ! ! 1 1 1 1 1 1 1 1 / / / / / / # # # # # # C C C C C C C C + + + + + + + + . . . . . . . . . . . . ,)+%g7 7 7      ))H H *)HVe5 e5 e5 e5 e5 e5 e5 e5P8' 8' 8' 8' 8' 8' 8' 8'v 	
.& .& .& .& .& .& .& .&b 	
x x x x x x x x~b+ b+ b+ b+ b+ b+ b+ b+J VXX@ @ @ @ @ @ @ @> VXX G. . . . . . . .b GV$ V$ V$ V$ V$ V$ V$ V$H6 6 6 6 6 6 6 6r Od+++	_u%%%    233B B B 43BJ GC C C CL   +,,60 60 -,60 60 60r"   