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

   2  [��cK9�@sddlZddlZddlZddlZddlZddlZddlZddlm	Z	ddl	m
   3  Z
   4  mZmZm
Z
mZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZm Z m!Z!m"Z"m#Z#m$Z$m%Z%m&Z&m'Z'm(Z(m)Z)m*Z*m+Z+m,Z,m-Z-m.Z.m/Z/m0Z0m1Z1m2Z2m3Z3m4Z4m5Z5m6Z6m7Z7m8Z8m9Z9m:Z:ddlm;Z;ddlm<Z<ddlm=Z=ddl;m>Z>m?Z?dd	l<m@Z@mAZAmBZBmCZCmDZDdd
   5  lmEZEddlEmFZFmGZGmHZHmIZImJZJmKZKddlLmMZMmNZNdd
lOmPZPmQZQeAZReSeB�ZTdZUejVe;jWdd�ZWgd�ZXe?d�Gdd�deY��ZZd�dd�Z[eWe[�d�dd��Z\d�dd�dd�Z]e>e?d�d�dd�dd���Z^eWe]�e^�Z_d�dd �Z`eWe`�d�d!d"��Zad�dd�d#d$�Zbe>e?d�d�dd�d%d&���ZceWeb�ec�Zdd�d'd(�ZeeWee�d�d)d*��Zfd�dd+�d,d-�ZgeWeg�d�d.d+�d/d0��Zhe?d�d1d2��Zid3d4�ZjeWej�d5d6��Zkd7d8�ZleWel�d9d:��Zmd�d;d<�ZneWen�d�d>d?��Zod�d@dA�ZpeWep�d�dBdC��Zqd�dDdE�ZreWer�d�dFdG��Zsd�dHdI�ZteWet�d�dKdL��Zud�dMdN�ZveWev�d�dOdP��Zwd�dQdR�ZxeWex�d�dSdT��Zyd�dUdV�ZzdWdX�Z{eWe{�dYdZ��Z|d�d[d\�Z}eWe}�d�d^d_��Z~ejd`kZ�e?d�e�d.fdadb��Z�dddc�ddde�Z�e>e?d�e�ddc�dfdg���Z�eWe��e��Z�dhdi�Z�e?d�djdk��Z�e?d�d�dldm��Z�e?d�d�dndo��Z�dpdq�Z�d�dd�drds�Z�e>e?d�d�dd�dtdu���Z�eWe��e��Z�d�dvdw�Z�eWe��d�dzd{��Z�d�d|d}�Z�eWe��d�d~d��Z�d�d�d��Z�eWe��d�d�d���Z�d�d��Z�eWe��d�d���Z�eCZ�Z�Z�Z�eDZ�Z�eKd.�Z�eKd�Z�d�d��Z�dd�l<Tdd�lETdd�lm�Z�dd�l�Tdd�lm�Z�dd�l�Tdd�lm�Z�dd�l�Tdd�lmOZOdd�lOTe�e��e�e<�e�eE�e�e��e�e��e�eO�dS)��N�)�
   6  multiarray)1�fastCopyAndTranspose�
ALLOW_THREADS�BUFSIZE�CLIP�MAXDIMS�MAY_SHARE_BOUNDS�MAY_SHARE_EXACT�RAISE�WRAP�arange�array�asarray�
   7  asanyarray�ascontiguousarray�asfortranarray�	broadcast�can_cast�compare_chararrays�concatenate�copyto�dot�dtype�empty�
   8  empty_like�flatiter�
   9  frombuffer�from_dlpack�fromfile�fromiter�
  10  fromstring�inner�lexsort�matmul�may_share_memory�min_scalar_type�ndarray�nditer�nested_iters�
promote_types�putmask�result_type�set_numeric_ops�
shares_memory�vdot�where�zeros�normalize_axis_index�_get_promotion_state�_set_promotion_state)�	overrides)�umath)�
  11  shape_base)�set_array_function_like_doc�
  12  set_module)�multiply�invert�sin�PINF�NAN)�numerictypes)�longlong�intc�int_�float_�complex_�bool_)�TooHardError�	AxisError)�errstate�_no_nep50_warning�numpy)�module)Z�newaxisr'rr(r)�ufuncr
rrrrrr1�
count_nonzerorrrr!rrrr0�argwhererrrr#r-rr*r&r,�	isfortranr�
  13  zeros_like�	ones_like�	correlate�convolver"r�outerr/�roll�rollaxis�moveaxis�cross�	tensordot�
little_endianr �array_equal�array_equiv�indices�fromfunction�isclose�isscalar�binary_repr�	base_repr�ones�identity�allcloserr+�flatnonzero�Inf�inf�infty�Infinity�nan�NaN�False_�True_�bitwise_notrrrrrr�ComplexWarning�full�	full_liker$r.r%r	r
  14  rFrGr3r4c@seZdZdZdS)rqz�
  15      The warning raised when casting a complex dtype to a real dtype.
  16  
  17      As implemented, casting a complex number to a real discards its imaginary
  18      part, but this behavior may not be what the user actually wants.
  19  
  20      N)�__name__�
  21  __module__�__qualname__�__doc__�rxrx��C:\Users\Jacks.GUTTSPC\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\numpy\core\numeric.pyrq=srqcC�|fS�Nrx��ar�order�subok�shaperxrxry�_zeros_like_dispatcherI�r��KTcCs4t|||||d�}td|jd�}tj||dd�|S)a
  22      Return an array of zeros with the same shape and type as a given array.
  23  
  24      Parameters
  25      ----------
  26      a : array_like
  27          The shape and data-type of `a` define these same attributes of
  28          the returned array.
  29      dtype : data-type, optional
  30          Overrides the data type of the result.
  31  
  32          .. versionadded:: 1.6.0
  33      order : {'C', 'F', 'A', or 'K'}, optional
  34          Overrides the memory layout of the result. 'C' means C-order,
  35          'F' means F-order, 'A' means 'F' if `a` is Fortran contiguous,
  36          'C' otherwise. 'K' means match the layout of `a` as closely
  37          as possible.
  38  
  39          .. versionadded:: 1.6.0
  40      subok : bool, optional.
  41          If True, then the newly created array will use the sub-class
  42          type of `a`, otherwise it will be a base-class array. Defaults
  43          to True.
  44      shape : int or sequence of ints, optional.
  45          Overrides the shape of the result. If order='K' and the number of
  46          dimensions is unchanged, will try to keep order, otherwise,
  47          order='C' is implied.
  48  
  49          .. versionadded:: 1.17.0
  50  
  51      Returns
  52      -------
  53      out : ndarray
  54          Array of zeros with the same shape and type as `a`.
  55  
  56      See Also
  57      --------
  58      empty_like : Return an empty array with shape and type of input.
  59      ones_like : Return an array of ones with shape and type of input.
  60      full_like : Return a new array with shape of input filled with value.
  61      zeros : Return a new array setting values to zero.
  62  
  63      Examples
  64      --------
  65      >>> x = np.arange(6)
  66      >>> x = x.reshape((2, 3))
  67      >>> x
  68      array([[0, 1, 2],
  69             [3, 4, 5]])
  70      >>> np.zeros_like(x)
  71      array([[0, 0, 0],
  72             [0, 0, 0]])
  73  
  74      >>> y = np.arange(3, dtype=float)
  75      >>> y
  76      array([0., 1., 2.])
  77      >>> np.zeros_like(y)
  78      array([0.,  0.,  0.])
  79  
  80      �rr~rr�r�r�unsafe��casting)rr1rrr)r}rr~rr��res�zrxrxryrQMs>rQ)�likecC�|fSr{rx)r�rr~r�rxrxry�_ones_dispatcher�r�r��CcCs8|durt||||d�St|||�}tj|ddd�|S)a�
  81      Return a new array of given shape and type, filled with ones.
  82  
  83      Parameters
  84      ----------
  85      shape : int or sequence of ints
  86          Shape of the new array, e.g., ``(2, 3)`` or ``2``.
  87      dtype : data-type, optional
  88          The desired data-type for the array, e.g., `numpy.int8`.  Default is
  89          `numpy.float64`.
  90      order : {'C', 'F'}, optional, default: C
  91          Whether to store multi-dimensional data in row-major
  92          (C-style) or column-major (Fortran-style) order in
  93          memory.
  94      ${ARRAY_FUNCTION_LIKE}
  95  
  96          .. versionadded:: 1.20.0
  97  
  98      Returns
  99      -------
 100      out : ndarray
 101          Array of ones with the given shape, dtype, and order.
 102  
 103      See Also
 104      --------
 105      ones_like : Return an array of ones with shape and type of input.
 106      empty : Return a new uninitialized array.
 107      zeros : Return a new array setting values to zero.
 108      full : Return a new array of given shape filled with value.
 109  
 110  
 111      Examples
 112      --------
 113      >>> np.ones(5)
 114      array([1., 1., 1., 1., 1.])
 115  
 116      >>> np.ones((5,), dtype=int)
 117      array([1, 1, 1, 1, 1])
 118  
 119      >>> np.ones((2, 1))
 120      array([[1.],
 121             [1.]])
 122  
 123      >>> s = (2,2)
 124      >>> np.ones(s)
 125      array([[1.,  1.],
 126             [1.,  1.]])
 127  
 128      N�rr~r�rr�r�)�_ones_with_likerrr)r�rr~r�r}rxrxryrd�s
 129  4rdcCrzr{rxr|rxrxry�_ones_like_dispatcher�r�r�cCs&t|||||d�}tj|ddd�|S)a
 130      Return an array of ones with the same shape and type as a given array.
 131  
 132      Parameters
 133      ----------
 134      a : array_like
 135          The shape and data-type of `a` define these same attributes of
 136          the returned array.
 137      dtype : data-type, optional
 138          Overrides the data type of the result.
 139  
 140          .. versionadded:: 1.6.0
 141      order : {'C', 'F', 'A', or 'K'}, optional
 142          Overrides the memory layout of the result. 'C' means C-order,
 143          'F' means F-order, 'A' means 'F' if `a` is Fortran contiguous,
 144          'C' otherwise. 'K' means match the layout of `a` as closely
 145          as possible.
 146  
 147          .. versionadded:: 1.6.0
 148      subok : bool, optional.
 149          If True, then the newly created array will use the sub-class
 150          type of `a`, otherwise it will be a base-class array. Defaults
 151          to True.
 152      shape : int or sequence of ints, optional.
 153          Overrides the shape of the result. If order='K' and the number of
 154          dimensions is unchanged, will try to keep order, otherwise,
 155          order='C' is implied.
 156  
 157          .. versionadded:: 1.17.0
 158  
 159      Returns
 160      -------
 161      out : ndarray
 162          Array of ones with the same shape and type as `a`.
 163  
 164      See Also
 165      --------
 166      empty_like : Return an empty array with shape and type of input.
 167      zeros_like : Return an array of zeros with shape and type of input.
 168      full_like : Return a new array with shape of input filled with value.
 169      ones : Return a new array setting values to one.
 170  
 171      Examples
 172      --------
 173      >>> x = np.arange(6)
 174      >>> x = x.reshape((2, 3))
 175      >>> x
 176      array([[0, 1, 2],
 177             [3, 4, 5]])
 178      >>> np.ones_like(x)
 179      array([[1, 1, 1],
 180             [1, 1, 1]])
 181  
 182      >>> y = np.arange(3, dtype=float)
 183      >>> y
 184      array([0., 1., 2.])
 185      >>> np.ones_like(y)
 186      array([1.,  1.,  1.])
 187  
 188      r�rr�r��rrr)r}rr~rr�r�rxrxryrR�s>rRcCs|fSr{rx)r��
 189  fill_valuerr~r�rxrxry�_full_dispatcherr�r�cCsP|dur
t|||||d�S|durt|�}|j}t|||�}tj||dd�|S)a�
 190      Return a new array of given shape and type, filled with `fill_value`.
 191  
 192      Parameters
 193      ----------
 194      shape : int or sequence of ints
 195          Shape of the new array, e.g., ``(2, 3)`` or ``2``.
 196      fill_value : scalar or array_like
 197          Fill value.
 198      dtype : data-type, optional
 199          The desired data-type for the array  The default, None, means
 200           ``np.array(fill_value).dtype``.
 201      order : {'C', 'F'}, optional
 202          Whether to store multidimensional data in C- or Fortran-contiguous
 203          (row- or column-wise) order in memory.
 204      ${ARRAY_FUNCTION_LIKE}
 205  
 206          .. versionadded:: 1.20.0
 207  
 208      Returns
 209      -------
 210      out : ndarray
 211          Array of `fill_value` with the given shape, dtype, and order.
 212  
 213      See Also
 214      --------
 215      full_like : Return a new array with shape of input filled with value.
 216      empty : Return a new uninitialized array.
 217      ones : Return a new array setting values to one.
 218      zeros : Return a new array setting values to zero.
 219  
 220      Examples
 221      --------
 222      >>> np.full((2, 2), np.inf)
 223      array([[inf, inf],
 224             [inf, inf]])
 225      >>> np.full((2, 2), 10)
 226      array([[10, 10],
 227             [10, 10]])
 228  
 229      >>> np.full((2, 2), [1, 2])
 230      array([[1, 2],
 231             [1, 2]])
 232  
 233      Nr�r�r�)�_full_with_likerrrrr)r�r�rr~r�r}rxrxryrr"s0rrcCrzr{rx)r}r�rr~rr�rxrxry�_full_like_dispatcherbr�r�cCs&t|||||d�}tj||dd�|S)af
 234      Return a full array with the same shape and type as a given array.
 235  
 236      Parameters
 237      ----------
 238      a : array_like
 239          The shape and data-type of `a` define these same attributes of
 240          the returned array.
 241      fill_value : array_like
 242          Fill value.
 243      dtype : data-type, optional
 244          Overrides the data type of the result.
 245      order : {'C', 'F', 'A', or 'K'}, optional
 246          Overrides the memory layout of the result. 'C' means C-order,
 247          'F' means F-order, 'A' means 'F' if `a` is Fortran contiguous,
 248          'C' otherwise. 'K' means match the layout of `a` as closely
 249          as possible.
 250      subok : bool, optional.
 251          If True, then the newly created array will use the sub-class
 252          type of `a`, otherwise it will be a base-class array. Defaults
 253          to True.
 254      shape : int or sequence of ints, optional.
 255          Overrides the shape of the result. If order='K' and the number of
 256          dimensions is unchanged, will try to keep order, otherwise,
 257          order='C' is implied.
 258  
 259          .. versionadded:: 1.17.0
 260  
 261      Returns
 262      -------
 263      out : ndarray
 264          Array of `fill_value` with the same shape and type as `a`.
 265  
 266      See Also
 267      --------
 268      empty_like : Return an empty array with shape and type of input.
 269      ones_like : Return an array of ones with shape and type of input.
 270      zeros_like : Return an array of zeros with shape and type of input.
 271      full : Return a new array of given shape filled with value.
 272  
 273      Examples
 274      --------
 275      >>> x = np.arange(6, dtype=int)
 276      >>> np.full_like(x, 1)
 277      array([1, 1, 1, 1, 1, 1])
 278      >>> np.full_like(x, 0.1)
 279      array([0, 0, 0, 0, 0, 0])
 280      >>> np.full_like(x, 0.1, dtype=np.double)
 281      array([0.1, 0.1, 0.1, 0.1, 0.1, 0.1])
 282      >>> np.full_like(x, np.nan, dtype=np.double)
 283      array([nan, nan, nan, nan, nan, nan])
 284  
 285      >>> y = np.arange(6, dtype=np.double)
 286      >>> np.full_like(y, 0.1)
 287      array([0.1, 0.1, 0.1, 0.1, 0.1, 0.1])
 288  
 289      >>> y = np.zeros([2, 2, 3], dtype=int)
 290      >>> np.full_like(y, [0, 0, 255])
 291      array([[[  0,   0, 255],
 292              [  0,   0, 255]],
 293             [[  0,   0, 255],
 294              [  0,   0, 255]]])
 295      r�r�r�r�)r}r�rr~rr�r�rxrxryrsfsArs)�keepdimscCrzr{rx)r}�axisr�rxrxry�_count_nonzero_dispatcher�r�r�FcCs`|dur|st�|�St|�}t�|jtj�r||j��k}n|jtj	dd�}|j
 296  |tj|d�S)a\
 297      Counts the number of non-zero values in the array ``a``.
 298  
 299      The word "non-zero" is in reference to the Python 2.x
 300      built-in method ``__nonzero__()`` (renamed ``__bool__()``
 301      in Python 3.x) of Python objects that tests an object's
 302      "truthfulness". For example, any number is considered
 303      truthful if it is nonzero, whereas any string is considered
 304      truthful if it is not the empty string. Thus, this function
 305      (recursively) counts how many elements in ``a`` (and in
 306      sub-arrays thereof) have their ``__nonzero__()`` or ``__bool__()``
 307      method evaluated to ``True``.
 308  
 309      Parameters
 310      ----------
 311      a : array_like
 312          The array for which to count non-zeros.
 313      axis : int or tuple, optional
 314          Axis or tuple of axes along which to count non-zeros.
 315          Default is None, meaning that non-zeros will be counted
 316          along a flattened version of ``a``.
 317  
 318          .. versionadded:: 1.12.0
 319  
 320      keepdims : bool, optional
 321          If this is set to True, the axes that are counted are left
 322          in the result as dimensions with size one. With this option,
 323          the result will broadcast correctly against the input array.
 324  
 325          .. versionadded:: 1.19.0
 326  
 327      Returns
 328      -------
 329      count : int or array of int
 330          Number of non-zero values in the array along a given axis.
 331          Otherwise, the total number of non-zero values in the array
 332          is returned.
 333  
 334      See Also
 335      --------
 336      nonzero : Return the coordinates of all the non-zero values.
 337  
 338      Examples
 339      --------
 340      >>> np.count_nonzero(np.eye(4))
 341      4
 342      >>> a = np.array([[0, 1, 7, 0],
 343      ...               [3, 0, 2, 19]])
 344      >>> np.count_nonzero(a)
 345      5
 346      >>> np.count_nonzero(a, axis=0)
 347      array([1, 1, 2, 1])
 348      >>> np.count_nonzero(a, axis=1)
 349      array([2, 3])
 350      >>> np.count_nonzero(a, axis=1, keepdims=True)
 351      array([[2],
 352             [3]])
 353      NF)�copy)r�rr�)rrNr�np�
 354  issubdtyper�	character�type�astyperE�sum�intp)r}r�r�Za_boolrxrxryrN�s<
 355  rNcCs|jjS)a
 356      Check if the array is Fortran contiguous but *not* C contiguous.
 357  
 358      This function is obsolete and, because of changes due to relaxed stride
 359      checking, its return value for the same array may differ for versions
 360      of NumPy >= 1.10.0 and previous versions. If you only want to check if an
 361      array is Fortran contiguous use ``a.flags.f_contiguous`` instead.
 362  
 363      Parameters
 364      ----------
 365      a : ndarray
 366          Input array.
 367  
 368      Returns
 369      -------
 370      isfortran : bool
 371          Returns True if the array is Fortran contiguous but *not* C contiguous.
 372  
 373  
 374      Examples
 375      --------
 376  
 377      np.array allows to specify whether the array is written in C-contiguous
 378      order (last index varies the fastest), or FORTRAN-contiguous order in
 379      memory (first index varies the fastest).
 380  
 381      >>> a = np.array([[1, 2, 3], [4, 5, 6]], order='C')
 382      >>> a
 383      array([[1, 2, 3],
 384             [4, 5, 6]])
 385      >>> np.isfortran(a)
 386      False
 387  
 388      >>> b = np.array([[1, 2, 3], [4, 5, 6]], order='F')
 389      >>> b
 390      array([[1, 2, 3],
 391             [4, 5, 6]])
 392      >>> np.isfortran(b)
 393      True
 394  
 395  
 396      The transpose of a C-ordered array is a FORTRAN-ordered array.
 397  
 398      >>> a = np.array([[1, 2, 3], [4, 5, 6]], order='C')
 399      >>> a
 400      array([[1, 2, 3],
 401             [4, 5, 6]])
 402      >>> np.isfortran(a)
 403      False
 404      >>> b = a.T
 405      >>> b
 406      array([[1, 4],
 407             [2, 5],
 408             [3, 6]])
 409      >>> np.isfortran(b)
 410      True
 411  
 412      C-ordered arrays evaluate as False even if they are also FORTRAN-ordered.
 413  
 414      >>> np.isfortran(np.array([1, 2], order='F'))
 415      False
 416  
 417      )�flags�fnc�r}rxrxryrP�sArPcCrzr{rxr�rxrxry�_argwhere_dispatcher>r�r�cCs<t�|�dkrt�|�}t|�dd�dd�fStt|��S)a�
 418      Find the indices of array elements that are non-zero, grouped by element.
 419  
 420      Parameters
 421      ----------
 422      a : array_like
 423          Input data.
 424  
 425      Returns
 426      -------
 427      index_array : (N, a.ndim) ndarray
 428          Indices of elements that are non-zero. Indices are grouped by element.
 429          This array will have shape ``(N, a.ndim)`` where ``N`` is the number of
 430          non-zero items.
 431  
 432      See Also
 433      --------
 434      where, nonzero
 435  
 436      Notes
 437      -----
 438      ``np.argwhere(a)`` is almost the same as ``np.transpose(np.nonzero(a))``,
 439      but produces a result of the correct shape for a 0D array.
 440  
 441      The output of ``argwhere`` is not suitable for indexing arrays.
 442      For this purpose use ``nonzero(a)`` instead.
 443  
 444      Examples
 445      --------
 446      >>> x = np.arange(6).reshape(2,3)
 447      >>> x
 448      array([[0, 1, 2],
 449             [3, 4, 5]])
 450      >>> np.argwhere(x>1)
 451      array([[0, 2],
 452             [1, 0],
 453             [1, 1],
 454             [1, 2]])
 455  
 456      rN)r��ndimr7�
 457  atleast_1drO�	transpose�nonzeror�rxrxryrOBs+
 458  rOcCrzr{rxr�rxrxry�_flatnonzero_dispatchertr�r�cCst�t�|��dS)aH
 459      Return indices that are non-zero in the flattened version of a.
 460  
 461      This is equivalent to ``np.nonzero(np.ravel(a))[0]``.
 462  
 463      Parameters
 464      ----------
 465      a : array_like
 466          Input data.
 467  
 468      Returns
 469      -------
 470      res : ndarray
 471          Output array, containing the indices of the elements of ``a.ravel()``
 472          that are non-zero.
 473  
 474      See Also
 475      --------
 476      nonzero : Return the indices of the non-zero elements of the input array.
 477      ravel : Return a 1-D array containing the elements of the input array.
 478  
 479      Examples
 480      --------
 481      >>> x = np.arange(-2, 3)
 482      >>> x
 483      array([-2, -1,  0,  1,  2])
 484      >>> np.flatnonzero(x)
 485      array([0, 1, 3, 4])
 486  
 487      Use the indices of the non-zero elements as an index array to extract
 488      these elements:
 489  
 490      >>> x.ravel()[np.flatnonzero(x)]
 491      array([-2, -1,  1,  2])
 492  
 493      r)r�r��ravelr�rxrxryrgxs&rgcC�||fSr{rx�r}�v�moderxrxry�_correlate_dispatcher��r��validcCst�|||�S)a�
 494      Cross-correlation of two 1-dimensional sequences.
 495  
 496      This function computes the correlation as generally defined in signal
 497      processing texts:
 498  
 499      .. math:: c_k = \sum_n a_{n+k} \cdot \overline{v}_n
 500  
 501      with a and v sequences being zero-padded where necessary and
 502      :math:`\overline x` denoting complex conjugation.
 503  
 504      Parameters
 505      ----------
 506      a, v : array_like
 507          Input sequences.
 508      mode : {'valid', 'same', 'full'}, optional
 509          Refer to the `convolve` docstring.  Note that the default
 510          is 'valid', unlike `convolve`, which uses 'full'.
 511      old_behavior : bool
 512          `old_behavior` was removed in NumPy 1.10. If you need the old
 513          behavior, use `multiarray.correlate`.
 514  
 515      Returns
 516      -------
 517      out : ndarray
 518          Discrete cross-correlation of `a` and `v`.
 519  
 520      See Also
 521      --------
 522      convolve : Discrete, linear convolution of two one-dimensional sequences.
 523      multiarray.correlate : Old, no conjugate, version of correlate.
 524      scipy.signal.correlate : uses FFT which has superior performance on large arrays. 
 525  
 526      Notes
 527      -----
 528      The definition of correlation above is not unique and sometimes correlation
 529      may be defined differently. Another common definition is:
 530  
 531      .. math:: c'_k = \sum_n a_{n} \cdot \overline{v_{n+k}}
 532  
 533      which is related to :math:`c_k` by :math:`c'_k = c_{-k}`.
 534  
 535      `numpy.correlate` may perform slowly in large arrays (i.e. n = 1e5) because it does
 536      not use the FFT to compute the convolution; in that case, `scipy.signal.correlate` might
 537      be preferable.
 538      
 539  
 540      Examples
 541      --------
 542      >>> np.correlate([1, 2, 3], [0, 1, 0.5])
 543      array([3.5])
 544      >>> np.correlate([1, 2, 3], [0, 1, 0.5], "same")
 545      array([2. ,  3.5,  3. ])
 546      >>> np.correlate([1, 2, 3], [0, 1, 0.5], "full")
 547      array([0.5,  2. ,  3.5,  3. ,  0. ])
 548  
 549      Using complex sequences:
 550  
 551      >>> np.correlate([1+1j, 2, 3-1j], [0, 1, 0.5j], 'full')
 552      array([ 0.5-0.5j,  1.0+0.j ,  1.5-1.5j,  3.0-1.j ,  0.0+0.j ])
 553  
 554      Note that you get the time reversed, complex conjugated result
 555      (:math:`\overline{c_{-k}}`) when the two input sequences a and v change 
 556      places:
 557  
 558      >>> np.correlate([0, 1, 0.5j], [1+1j, 2, 3-1j], 'full')
 559      array([ 0.0+0.j ,  3.0+1.j ,  1.5+1.5j,  1.0+0.j ,  0.5+0.5j])
 560  
 561      )r�
 562  correlate2r�rxrxryrS�sGrScCr�r{rxr�rxrxry�_convolve_dispatcher�r�r�cCsxt|ddd�t|ddd�}}t|�t|�kr||}}t|�dkr&td��t|�dkr0td��t�||ddd�|�S)	a
 563      Returns the discrete, linear convolution of two one-dimensional sequences.
 564  
 565      The convolution operator is often seen in signal processing, where it
 566      models the effect of a linear time-invariant system on a signal [1]_.  In
 567      probability theory, the sum of two independent random variables is
 568      distributed according to the convolution of their individual
 569      distributions.
 570  
 571      If `v` is longer than `a`, the arrays are swapped before computation.
 572  
 573      Parameters
 574      ----------
 575      a : (N,) array_like
 576          First one-dimensional input array.
 577      v : (M,) array_like
 578          Second one-dimensional input array.
 579      mode : {'full', 'valid', 'same'}, optional
 580          'full':
 581            By default, mode is 'full'.  This returns the convolution
 582            at each point of overlap, with an output shape of (N+M-1,). At
 583            the end-points of the convolution, the signals do not overlap
 584            completely, and boundary effects may be seen.
 585  
 586          'same':
 587            Mode 'same' returns output of length ``max(M, N)``.  Boundary
 588            effects are still visible.
 589  
 590          'valid':
 591            Mode 'valid' returns output of length
 592            ``max(M, N) - min(M, N) + 1``.  The convolution product is only given
 593            for points where the signals overlap completely.  Values outside
 594            the signal boundary have no effect.
 595  
 596      Returns
 597      -------
 598      out : ndarray
 599          Discrete, linear convolution of `a` and `v`.
 600  
 601      See Also
 602      --------
 603      scipy.signal.fftconvolve : Convolve two arrays using the Fast Fourier
 604                                 Transform.
 605      scipy.linalg.toeplitz : Used to construct the convolution operator.
 606      polymul : Polynomial multiplication. Same output as convolve, but also
 607                accepts poly1d objects as input.
 608  
 609      Notes
 610      -----
 611      The discrete convolution operation is defined as
 612  
 613      .. math:: (a * v)_n = \sum_{m = -\infty}^{\infty} a_m v_{n - m}
 614  
 615      It can be shown that a convolution :math:`x(t) * y(t)` in time/space
 616      is equivalent to the multiplication :math:`X(f) Y(f)` in the Fourier
 617      domain, after appropriate padding (padding is necessary to prevent
 618      circular convolution).  Since multiplication is more efficient (faster)
 619      than convolution, the function `scipy.signal.fftconvolve` exploits the
 620      FFT to calculate the convolution of large data-sets.
 621  
 622      References
 623      ----------
 624      .. [1] Wikipedia, "Convolution",
 625          https://en.wikipedia.org/wiki/Convolution
 626  
 627      Examples
 628      --------
 629      Note how the convolution operator flips the second array
 630      before "sliding" the two across one another:
 631  
 632      >>> np.convolve([1, 2, 3], [0, 1, 0.5])
 633      array([0. , 1. , 2.5, 4. , 1.5])
 634  
 635      Only return the middle values of the convolution.
 636      Contains boundary effects, where zeros are taken
 637      into account:
 638  
 639      >>> np.convolve([1,2,3],[0,1,0.5], 'same')
 640      array([1. ,  2.5,  4. ])
 641  
 642      The two arrays are of the same length, so there
 643      is only one position where they completely overlap:
 644  
 645      >>> np.convolve([1,2,3],[0,1,0.5], 'valid')
 646      array([2.5])
 647  
 648      Fr)r��ndminrza cannot be emptyzv cannot be emptyN�����)r�len�
 649  ValueErrorrrSr�rxrxryrT�sY
 650  rTcCs
 651  |||fSr{rx�r}�b�outrxrxry�_outer_dispatcherVs
 652  r�cCs<t|�}t|�}t|��dd�tf|��tdd�f|�S)a
 653  
 654      Compute the outer product of two vectors.
 655  
 656      Given two vectors, ``a = [a0, a1, ..., aM]`` and
 657      ``b = [b0, b1, ..., bN]``,
 658      the outer product [1]_ is::
 659  
 660        [[a0*b0  a0*b1 ... a0*bN ]
 661         [a1*b0    .
 662         [ ...          .
 663         [aM*b0            aM*bN ]]
 664  
 665      Parameters
 666      ----------
 667      a : (M,) array_like
 668          First input vector.  Input is flattened if
 669          not already 1-dimensional.
 670      b : (N,) array_like
 671          Second input vector.  Input is flattened if
 672          not already 1-dimensional.
 673      out : (M, N) ndarray, optional
 674          A location where the result is stored
 675  
 676          .. versionadded:: 1.9.0
 677  
 678      Returns
 679      -------
 680      out : (M, N) ndarray
 681          ``out[i, j] = a[i] * b[j]``
 682  
 683      See also
 684      --------
 685      inner
 686      einsum : ``einsum('i,j->ij', a.ravel(), b.ravel())`` is the equivalent.
 687      ufunc.outer : A generalization to dimensions other than 1D and other
 688                    operations. ``np.multiply.outer(a.ravel(), b.ravel())``
 689                    is the equivalent.
 690      tensordot : ``np.tensordot(a.ravel(), b.ravel(), axes=((), ()))``
 691                  is the equivalent.
 692  
 693      References
 694      ----------
 695      .. [1] : G. H. Golub and C. F. Van Loan, *Matrix Computations*, 3rd
 696               ed., Baltimore, MD, Johns Hopkins University Press, 1996,
 697               pg. 8.
 698  
 699      Examples
 700      --------
 701      Make a (*very* coarse) grid for computing a Mandelbrot set:
 702  
 703      >>> rl = np.outer(np.ones((5,)), np.linspace(-2, 2, 5))
 704      >>> rl
 705      array([[-2., -1.,  0.,  1.,  2.],
 706             [-2., -1.,  0.,  1.,  2.],
 707             [-2., -1.,  0.,  1.,  2.],
 708             [-2., -1.,  0.,  1.,  2.],
 709             [-2., -1.,  0.,  1.,  2.]])
 710      >>> im = np.outer(1j*np.linspace(2, -2, 5), np.ones((5,)))
 711      >>> im
 712      array([[0.+2.j, 0.+2.j, 0.+2.j, 0.+2.j, 0.+2.j],
 713             [0.+1.j, 0.+1.j, 0.+1.j, 0.+1.j, 0.+1.j],
 714             [0.+0.j, 0.+0.j, 0.+0.j, 0.+0.j, 0.+0.j],
 715             [0.-1.j, 0.-1.j, 0.-1.j, 0.-1.j, 0.-1.j],
 716             [0.-2.j, 0.-2.j, 0.-2.j, 0.-2.j, 0.-2.j]])
 717      >>> grid = rl + im
 718      >>> grid
 719      array([[-2.+2.j, -1.+2.j,  0.+2.j,  1.+2.j,  2.+2.j],
 720             [-2.+1.j, -1.+1.j,  0.+1.j,  1.+1.j,  2.+1.j],
 721             [-2.+0.j, -1.+0.j,  0.+0.j,  1.+0.j,  2.+0.j],
 722             [-2.-1.j, -1.-1.j,  0.-1.j,  1.-1.j,  2.-1.j],
 723             [-2.-2.j, -1.-2.j,  0.-2.j,  1.-2.j,  2.-2.j]])
 724  
 725      An example using a "vector" of letters:
 726  
 727      >>> x = np.array(['a', 'b', 'c'], dtype=object)
 728      >>> np.outer(x, [1, 2, 3])
 729      array([['a', 'aa', 'aaa'],
 730             ['b', 'bb', 'bbb'],
 731             ['c', 'cc', 'ccc']], dtype=object)
 732  
 733      N)rr:r�rLr�rxrxryrUZsS,rUcCr�r{rx)r}r��axesrxrxry�_tensordot_dispatcher�r�r��csdzt|�Wntytt|d���ttd|���Ynw|\��z
 734  t��}t���Wnty;�g�d}Ynwz
 735  t��}t���WntyT�g�d}Ynwt|�t|�}}|j�|j}|j�|j}d}||krsd}n3t|�D].}��|��|kr�d}n�|dkr��||7<�|dkr��||7<qw|s�t	d���fdd�t|�D�}	|	�}
 736  d}�D]}|�|9}q�t
 737  t��fdd�|	D���|f}
�fd	d�|	D�}�fd
 738  d�t|�D�}	�|	}d}�D]}|�|9}q�|t
 739  t��fdd�|	D���f}�fdd�|	D�}|�
|
 740  ��|
�}|�
|��|�}t||�}|�||�S)
a�
 741      Compute tensor dot product along specified axes.
 742  
 743      Given two tensors, `a` and `b`, and an array_like object containing
 744      two array_like objects, ``(a_axes, b_axes)``, sum the products of
 745      `a`'s and `b`'s elements (components) over the axes specified by
 746      ``a_axes`` and ``b_axes``. The third argument can be a single non-negative
 747      integer_like scalar, ``N``; if it is such, then the last ``N`` dimensions
 748      of `a` and the first ``N`` dimensions of `b` are summed over.
 749  
 750      Parameters
 751      ----------
 752      a, b : array_like
 753          Tensors to "dot".
 754  
 755      axes : int or (2,) array_like
 756          * integer_like
 757            If an int N, sum over the last N axes of `a` and the first N axes
 758            of `b` in order. The sizes of the corresponding axes must match.
 759          * (2,) array_like
 760            Or, a list of axes to be summed over, first sequence applying to `a`,
 761            second to `b`. Both elements array_like must be of the same length.
 762  
 763      Returns
 764      -------
 765      output : ndarray
 766          The tensor dot product of the input.
 767  
 768      See Also
 769      --------
 770      dot, einsum
 771  
 772      Notes
 773      -----
 774      Three common use cases are:
 775          * ``axes = 0`` : tensor product :math:`a\otimes b`
 776          * ``axes = 1`` : tensor dot product :math:`a\cdot b`
 777          * ``axes = 2`` : (default) tensor double contraction :math:`a:b`
 778  
 779      When `axes` is integer_like, the sequence for evaluation will be: first
 780      the -Nth axis in `a` and 0th axis in `b`, and the -1th axis in `a` and
 781      Nth axis in `b` last.
 782  
 783      When there is more than one axis to sum over - and they are not the last
 784      (first) axes of `a` (`b`) - the argument `axes` should consist of
 785      two sequences of the same length, with the first axis to sum over given
 786      first in both sequences, the second axis second, and so forth.
 787  
 788      The shape of the result consists of the non-contracted axes of the
 789      first tensor, followed by the non-contracted axes of the second.
 790  
 791      Examples
 792      --------
 793      A "traditional" example:
 794  
 795      >>> a = np.arange(60.).reshape(3,4,5)
 796      >>> b = np.arange(24.).reshape(4,3,2)
 797      >>> c = np.tensordot(a,b, axes=([1,0],[0,1]))
 798      >>> c.shape
 799      (5, 2)
 800      >>> c
 801      array([[4400., 4730.],
 802             [4532., 4874.],
 803             [4664., 5018.],
 804             [4796., 5162.],
 805             [4928., 5306.]])
 806      >>> # A slower but equivalent way of computing the same...
 807      >>> d = np.zeros((5,2))
 808      >>> for i in range(5):
 809      ...   for j in range(2):
 810      ...     for k in range(3):
 811      ...       for n in range(4):
 812      ...         d[i,j] += a[k,n,i] * b[n,k,j]
 813      >>> c == d
 814      array([[ True,  True],
 815             [ True,  True],
 816             [ True,  True],
 817             [ True,  True],
 818             [ True,  True]])
 819  
 820      An extended example taking advantage of the overloading of + and \*:
 821  
 822      >>> a = np.array(range(1, 9))
 823      >>> a.shape = (2, 2, 2)
 824      >>> A = np.array(('a', 'b', 'c', 'd'), dtype=object)
 825      >>> A.shape = (2, 2)
 826      >>> a; A
 827      array([[[1, 2],
 828              [3, 4]],
 829             [[5, 6],
 830              [7, 8]]])
 831      array([['a', 'b'],
 832             ['c', 'd']], dtype=object)
 833  
 834      >>> np.tensordot(a, A) # third argument default is 2 for double-contraction
 835      array(['abbcccdddd', 'aaaaabbbbbbcccccccdddddddd'], dtype=object)
 836  
 837      >>> np.tensordot(a, A, 1)
 838      array([[['acc', 'bdd'],
 839              ['aaacccc', 'bbbdddd']],
 840             [['aaaaacccccc', 'bbbbbdddddd'],
 841              ['aaaaaaacccccccc', 'bbbbbbbdddddddd']]], dtype=object)
 842  
 843      >>> np.tensordot(a, A, 0) # tensor product (result too long to incl.)
 844      array([[[[['a', 'b'],
 845                ['c', 'd']],
 846                ...
 847  
 848      >>> np.tensordot(a, A, (0, 1))
 849      array([[['abbbbb', 'cddddd'],
 850              ['aabbbbbb', 'ccdddddd']],
 851             [['aaabbbbbbb', 'cccddddddd'],
 852              ['aaaabbbbbbbb', 'ccccdddddddd']]], dtype=object)
 853  
 854      >>> np.tensordot(a, A, (2, 1))
 855      array([[['abb', 'cdd'],
 856              ['aaabbbb', 'cccdddd']],
 857             [['aaaaabbbbbb', 'cccccdddddd'],
 858              ['aaaaaaabbbbbbbb', 'cccccccdddddddd']]], dtype=object)
 859  
 860      >>> np.tensordot(a, A, ((0, 1), (0, 1)))
 861      array(['abbbcccccddddddd', 'aabbbbccccccdddddddd'], dtype=object)
 862  
 863      >>> np.tensordot(a, A, ((2, 1), (1, 0)))
 864      array(['acccbbdddd', 'aaaaacccccccbbbbbbdddddddd'], dtype=object)
 865  
 866      rrTFzshape-mismatch for sumc�g|]}|�vr|�qSrxrx��.0�k)�axes_arxry�
 867  <listcomp>a�ztensordot.<locals>.<listcomp>c�g|]}�|�qSrxrx�r��ax��as_rxryr�f�cr�rxrx�r�r�r�rxryr�gr�cr�rxrxr�)�axes_brxryr�ir�cr�rxrxr���bsrxryr�nr�cr�rxrxr�r�rxryr�or�)�iter�	Exception�list�ranger��	TypeErrorrr�r�r��intr:�reducer��reshaper)r}r�r��na�nb�nda�ndb�equalr��notinZ	newaxes_a�N2r�Z
 868  newshape_aZoldaZ	newaxes_bZ
 869  newshape_bZoldb�at�btr�rx)r�r�r�r�ryrZ�sv����  
 870  rZcCrzr{rx)r}�shiftr�rxrxry�_roll_dispatcherwr�r�c
Cs,t|�}|durt|��|d��|j�St||jdd�}t||�}|jdkr*td��dd�t	|j�D�}|D]\}}|||7<q6t
 871  d�t
 872  d�ffg|j}|��D]'\}}||j|p_d;}|r{t
 873  d|�t
 874  |d�ft
 875  |d�t
 876  d|�ff||<qTt|�}	t
j|�D]}
 877  t|
 878  �\}}|||	|<q�|	S)	a)
 879      Roll array elements along a given axis.
 880  
 881      Elements that roll beyond the last position are re-introduced at
 882      the first.
 883  
 884      Parameters
 885      ----------
 886      a : array_like
 887          Input array.
 888      shift : int or tuple of ints
 889          The number of places by which elements are shifted.  If a tuple,
 890          then `axis` must be a tuple of the same size, and each of the
 891          given axes is shifted by the corresponding number.  If an int
 892          while `axis` is a tuple of ints, then the same value is used for
 893          all given axes.
 894      axis : int or tuple of ints, optional
 895          Axis or axes along which elements are shifted.  By default, the
 896          array is flattened before shifting, after which the original
 897          shape is restored.
 898  
 899      Returns
 900      -------
 901      res : ndarray
 902          Output array, with the same shape as `a`.
 903  
 904      See Also
 905      --------
 906      rollaxis : Roll the specified axis backwards, until it lies in a
 907                 given position.
 908  
 909      Notes
 910      -----
 911      .. versionadded:: 1.12.0
 912  
 913      Supports rolling over multiple dimensions simultaneously.
 914  
 915      Examples
 916      --------
 917      >>> x = np.arange(10)
 918      >>> np.roll(x, 2)
 919      array([8, 9, 0, 1, 2, 3, 4, 5, 6, 7])
 920      >>> np.roll(x, -2)
 921      array([2, 3, 4, 5, 6, 7, 8, 9, 0, 1])
 922  
 923      >>> x2 = np.reshape(x, (2, 5))
 924      >>> x2
 925      array([[0, 1, 2, 3, 4],
 926             [5, 6, 7, 8, 9]])
 927      >>> np.roll(x2, 1)
 928      array([[9, 0, 1, 2, 3],
 929             [4, 5, 6, 7, 8]])
 930      >>> np.roll(x2, -1)
 931      array([[1, 2, 3, 4, 5],
 932             [6, 7, 8, 9, 0]])
 933      >>> np.roll(x2, 1, axis=0)
 934      array([[5, 6, 7, 8, 9],
 935             [0, 1, 2, 3, 4]])
 936      >>> np.roll(x2, -1, axis=0)
 937      array([[5, 6, 7, 8, 9],
 938             [0, 1, 2, 3, 4]])
 939      >>> np.roll(x2, 1, axis=1)
 940      array([[4, 0, 1, 2, 3],
 941             [9, 5, 6, 7, 8]])
 942      >>> np.roll(x2, -1, axis=1)
 943      array([[1, 2, 3, 4, 0],
 944             [6, 7, 8, 9, 5]])
 945      >>> np.roll(x2, (1, 1), axis=(1, 0))
 946      array([[9, 5, 6, 7, 8],
 947             [4, 0, 1, 2, 3]])
 948      >>> np.roll(x2, (2, 1), axis=(1, 0))
 949      array([[8, 9, 5, 6, 7],
 950             [3, 4, 0, 1, 2]])
 951  
 952      NrT)�allow_duplicaterz4'shift' and 'axis' should be scalars or 1D sequencescSsi|]}|d�qS�rrxr�rxrxry�
 953  <dictcomp>�szroll.<locals>.<dictcomp>)rrVr�r�r��normalize_axis_tupler�rr�r��slice�itemsr�	itertools�product�zip)
r}r�r�Zbroadcasted�shifts�shr�Zrolls�offset�resultr^Z	arr_index�	res_indexrxrxryrV{s2M
 954  
 955  ���rVcCrzr{rx)r}r��startrxrxry�_rollaxis_dispatcher�r�r�cCs�|j}t||�}|dkr||7}d}d|kr|dks-nt|d|d|d|f��||kr5|d8}||kr=|dSttd|��}|�|�|�||�|�|�S)a+
 956  
 957      Roll the specified axis backwards, until it lies in a given position.
 958  
 959      This function continues to be supported for backward compatibility, but you
 960      should prefer `moveaxis`. The `moveaxis` function was added in NumPy
 961      1.11.
 962  
 963      Parameters
 964      ----------
 965      a : ndarray
 966          Input array.
 967      axis : int
 968          The axis to be rolled. The positions of the other axes do not
 969          change relative to one another.
 970      start : int, optional
 971          When ``start <= axis``, the axis is rolled back until it lies in
 972          this position. When ``start > axis``, the axis is rolled until it
 973          lies before this position. The default, 0, results in a "complete"
 974          roll. The following table describes how negative values of ``start``
 975          are interpreted:
 976  
 977          .. table::
 978             :align: left
 979  
 980             +-------------------+----------------------+
 981             |     ``start``     | Normalized ``start`` |
 982             +===================+======================+
 983             | ``-(arr.ndim+1)`` | raise ``AxisError``  |
 984             +-------------------+----------------------+
 985             | ``-arr.ndim``     | 0                    |
 986             +-------------------+----------------------+
 987             | |vdots|           | |vdots|              |
 988             +-------------------+----------------------+
 989             | ``-1``            | ``arr.ndim-1``       |
 990             +-------------------+----------------------+
 991             | ``0``             | ``0``                |
 992             +-------------------+----------------------+
 993             | |vdots|           | |vdots|              |
 994             +-------------------+----------------------+
 995             | ``arr.ndim``      | ``arr.ndim``         |
 996             +-------------------+----------------------+
 997             | ``arr.ndim + 1``  | raise ``AxisError``  |
 998             +-------------------+----------------------+
 999             
1000          .. |vdots|   unicode:: U+22EE .. Vertical Ellipsis
1001  
1002      Returns
1003      -------
1004      res : ndarray
1005          For NumPy >= 1.10.0 a view of `a` is always returned. For earlier
1006          NumPy versions a view of `a` is returned only if the order of the
1007          axes is changed, otherwise the input array is returned.
1008  
1009      See Also
1010      --------
1011      moveaxis : Move array axes to new positions.
1012      roll : Roll the elements of an array by a number of positions along a
1013          given axis.
1014  
1015      Examples
1016      --------
1017      >>> a = np.ones((3,4,5,6))
1018      >>> np.rollaxis(a, 3, 1).shape
1019      (3, 6, 4, 5)
1020      >>> np.rollaxis(a, 2).shape
1021      (5, 3, 4, 6)
1022      >>> np.rollaxis(a, 1, 4).shape
1023      (3, 5, 6, 4)
1024  
1025      rz5'%s' arg requires %d <= %s < %d, but %d was passed inrr�.)r�r2rGr�r��remove�insertr�)r}r�r��n�msgr�rxrxryrW�sH
1026  
1027  
1028  rWcs�t|�ttfvrzt�|�g}Wn	tyYnwt��fdd�|D��}|s?tt|��t|�kr?�r;td�	����td��|S)a�
1029      Normalizes an axis argument into a tuple of non-negative integer axes.
1030  
1031      This handles shorthands such as ``1`` and converts them to ``(1,)``,
1032      as well as performing the handling of negative indices covered by
1033      `normalize_axis_index`.
1034  
1035      By default, this forbids axes from being specified multiple times.
1036  
1037      Used internally by multi-axis-checking logic.
1038  
1039      .. versionadded:: 1.13.0
1040  
1041      Parameters
1042      ----------
1043      axis : int, iterable of int
1044          The un-normalized index or indices of the axis.
1045      ndim : int
1046          The number of dimensions of the array that `axis` should be normalized
1047          against.
1048      argname : str, optional
1049          A prefix to put before the error message, typically the name of the
1050          argument.
1051      allow_duplicate : bool, optional
1052          If False, the default, disallow an axis from being specified twice.
1053  
1054      Returns
1055      -------
1056      normalized_axes : tuple of int
1057          The normalized axis index, such that `0 <= normalized_axis < ndim`
1058  
1059      Raises
1060      ------
1061      AxisError
1062          If any axis provided is out of range
1063      ValueError
1064          If an axis is repeated
1065  
1066      See also
1067      --------
1068      normalize_axis_index : normalizing a single scalar axis
1069      csg|]}t|����qSrx)r2r���argnamer�rxryr�vr�z(normalize_axis_tuple.<locals>.<listcomp>zrepeated axis in `{}` argumentz
repeated axis)
1070  r��tupler��operator�indexr�r��setr��format)r�r�r�r�rxr�ryr�Ds,�r�cCrzr{rx)r}�source�destinationrxrxry�_moveaxis_dispatcherr�rcs�z|j}Wntyt|�}|j}Ynwt�|jd��t||jd�}t��t|�kr0td���fdd�t|j�D�}tt	|���D]
1071  \}}|�
1072  ||�qC||�}|S)aw
1073      Move axes of an array to new positions.
1074  
1075      Other axes remain in their original order.
1076  
1077      .. versionadded:: 1.11.0
1078  
1079      Parameters
1080      ----------
1081      a : np.ndarray
1082          The array whose axes should be reordered.
1083      source : int or sequence of int
1084          Original positions of the axes to move. These must be unique.
1085      destination : int or sequence of int
1086          Destination positions for each of the original axes. These must also be
1087          unique.
1088  
1089      Returns
1090      -------
1091      result : np.ndarray
1092          Array with moved axes. This array is a view of the input array.
1093  
1094      See Also
1095      --------
1096      transpose : Permute the dimensions of an array.
1097      swapaxes : Interchange two axes of an array.
1098  
1099      Examples
1100      --------
1101      >>> x = np.zeros((3, 4, 5))
1102      >>> np.moveaxis(x, 0, -1).shape
1103      (4, 5, 3)
1104      >>> np.moveaxis(x, -1, 0).shape
1105      (5, 3, 4)
1106  
1107      These all achieve the same result:
1108  
1109      >>> np.transpose(x).shape
1110      (5, 4, 3)
1111      >>> np.swapaxes(x, 0, -1).shape
1112      (5, 4, 3)
1113      >>> np.moveaxis(x, [0, 1], [-1, -2]).shape
1114      (5, 4, 3)
1115      >>> np.moveaxis(x, [0, 1, 2], [-1, -2, -3]).shape
1116      (5, 4, 3)
1117  
1118      r�rzJ`source` and `destination` arguments must have the same number of elementscr�rxrx)r�r��r�rxryr��r�zmoveaxis.<locals>.<listcomp>)r��AttributeErrorrr�r�r�r�r��sortedr�r�)r}r�rr�r~�dest�srcr�rxrryrX�s1
1119  
1120  �rXcCr�r{rx)r}r��axisa�axisb�axiscr�rxrxry�_cross_dispatcher�r�r
1121  r�cCs�|dur|fd\}}}t|�}t|�}t||jdd�}t||jdd�}t||d�}t||d�}d}|jddvs@|jddvrDt|��t|d	|d	�j}|jddks\|jddkri|d
1122  7}t|t|�dd�}t|j	|j	�}t
1123  ||�}	|�|�}|�|�}|d	}
1124  |d}|jddkr�|d
}|d	}
|d}|jddkr�|d
}|	jdkr�|	jddkr�|	d	}|	d}|	d
}|jddk�r|jddkr�t|
1125  ||	d�|	||
8}	|	S|jddks�J�t|||d�t|
1126  ||d�t
||d�t|
1127  ||d�|||
8}ns|jddk�sJ�|jddk�rNt|||d�t||�}||8}t||
|d�t|
1128  ||d�||8}t|
1129  ||d�t||
|d�||8}n+|jddk�sXJ�t|||d�t
||d�t||
|d�t|
1130  ||d�|||
8}t|	d|�S)a 
1131      Return the cross product of two (arrays of) vectors.
1132  
1133      The cross product of `a` and `b` in :math:`R^3` is a vector perpendicular
1134      to both `a` and `b`.  If `a` and `b` are arrays of vectors, the vectors
1135      are defined by the last axis of `a` and `b` by default, and these axes
1136      can have dimensions 2 or 3.  Where the dimension of either `a` or `b` is
1137      2, the third component of the input vector is assumed to be zero and the
1138      cross product calculated accordingly.  In cases where both input vectors
1139      have dimension 2, the z-component of the cross product is returned.
1140  
1141      Parameters
1142      ----------
1143      a : array_like
1144          Components of the first vector(s).
1145      b : array_like
1146          Components of the second vector(s).
1147      axisa : int, optional
1148          Axis of `a` that defines the vector(s).  By default, the last axis.
1149      axisb : int, optional
1150          Axis of `b` that defines the vector(s).  By default, the last axis.
1151      axisc : int, optional
1152          Axis of `c` containing the cross product vector(s).  Ignored if
1153          both input vectors have dimension 2, as the return is scalar.
1154          By default, the last axis.
1155      axis : int, optional
1156          If defined, the axis of `a`, `b` and `c` that defines the vector(s)
1157          and cross product(s).  Overrides `axisa`, `axisb` and `axisc`.
1158  
1159      Returns
1160      -------
1161      c : ndarray
1162          Vector cross product(s).
1163  
1164      Raises
1165      ------
1166      ValueError
1167          When the dimension of the vector(s) in `a` and/or `b` does not
1168          equal 2 or 3.
1169  
1170      See Also
1171      --------
1172      inner : Inner product
1173      outer : Outer product.
1174      ix_ : Construct index arrays.
1175  
1176      Notes
1177      -----
1178      .. versionadded:: 1.9.0
1179  
1180      Supports full broadcasting of the inputs.
1181  
1182      Examples
1183      --------
1184      Vector cross-product.
1185  
1186      >>> x = [1, 2, 3]
1187      >>> y = [4, 5, 6]
1188      >>> np.cross(x, y)
1189      array([-3,  6, -3])
1190  
1191      One vector with dimension 2.
1192  
1193      >>> x = [1, 2]
1194      >>> y = [4, 5, 6]
1195      >>> np.cross(x, y)
1196      array([12, -6, -3])
1197  
1198      Equivalently:
1199  
1200      >>> x = [1, 2, 0]
1201      >>> y = [4, 5, 6]
1202      >>> np.cross(x, y)
1203      array([12, -6, -3])
1204  
1205      Both vectors with dimension 2.
1206  
1207      >>> x = [1,2]
1208      >>> y = [4,5]
1209      >>> np.cross(x, y)
1210      array(-3)
1211  
1212      Multiple vector cross-products. Note that the direction of the cross
1213      product vector is defined by the *right-hand rule*.
1214  
1215      >>> x = np.array([[1,2,3], [4,5,6]])
1216      >>> y = np.array([[4,5,6], [1,2,3]])
1217      >>> np.cross(x, y)
1218      array([[-3,  6, -3],
1219             [ 3, -6,  3]])
1220  
1221      The orientation of `c` can be changed using the `axisc` keyword.
1222  
1223      >>> np.cross(x, y, axisc=0)
1224      array([[-3,  3],
1225             [ 6, -6],
1226             [-3,  3]])
1227  
1228      Change the vector definition of `x` and `y` using `axisa` and `axisb`.
1229  
1230      >>> x = np.array([[1,2,3], [4,5,6], [7, 8, 9]])
1231      >>> y = np.array([[7, 8, 9], [4,5,6], [1,2,3]])
1232      >>> np.cross(x, y)
1233      array([[ -6,  12,  -6],
1234             [  0,   0,   0],
1235             [  6, -12,   6]])
1236      >>> np.cross(x, y, axisa=0, axisb=0)
1237      array([[-24,  48, -24],
1238             [-30,  60, -30],
1239             [-36,  72, -36]])
1240  
1241      N�r)�
1242  msg_prefixrr�zDincompatible dimensions for cross product
1243  (dimension must be 2 or 3))r�r).r)rr	).r).r�rr�)r�)rr2r�rXr�r�rr�r*rrr�r:�negativer)r}r�rrr	r�r�r�r�cp�a0�a1�a2�b0�b1�b2�cp0Zcp1Zcp2�tmprxrxryrY�sxr
1244  
1245  
1246  
1247  rY�littlec	Cs�t|�}t|�}d|}|rt�}n	t|f||d�}t|�D](\}}t||d��|d|�|f||dd��}|rC||f}q|||<q|S)a�
1248      Return an array representing the indices of a grid.
1249  
1250      Compute an array where the subarrays contain index values 0, 1, ...
1251      varying only along the corresponding axis.
1252  
1253      Parameters
1254      ----------
1255      dimensions : sequence of ints
1256          The shape of the grid.
1257      dtype : dtype, optional
1258          Data type of the result.
1259      sparse : boolean, optional
1260          Return a sparse representation of the grid instead of a dense
1261          representation. Default is False.
1262  
1263          .. versionadded:: 1.17
1264  
1265      Returns
1266      -------
1267      grid : one ndarray or tuple of ndarrays
1268          If sparse is False:
1269              Returns one array of grid indices,
1270              ``grid.shape = (len(dimensions),) + tuple(dimensions)``.
1271          If sparse is True:
1272              Returns a tuple of arrays, with
1273              ``grid[i].shape = (1, ..., 1, dimensions[i], 1, ..., 1)`` with
1274              dimensions[i] in the ith place
1275  
1276      See Also
1277      --------
1278      mgrid, ogrid, meshgrid
1279  
1280      Notes
1281      -----
1282      The output shape in the dense case is obtained by prepending the number
1283      of dimensions in front of the tuple of dimensions, i.e. if `dimensions`
1284      is a tuple ``(r0, ..., rN-1)`` of length ``N``, the output shape is
1285      ``(N, r0, ..., rN-1)``.
1286  
1287      The subarrays ``grid[k]`` contains the N-D array of indices along the
1288      ``k-th`` axis. Explicitly::
1289  
1290          grid[k, i0, i1, ..., iN-1] = ik
1291  
1292      Examples
1293      --------
1294      >>> grid = np.indices((2, 3))
1295      >>> grid.shape
1296      (2, 2, 3)
1297      >>> grid[0]        # row indices
1298      array([[0, 0, 0],
1299             [1, 1, 1]])
1300      >>> grid[1]        # column indices
1301      array([[0, 1, 2],
1302             [0, 1, 2]])
1303  
1304      The indices can be used as an index into an array.
1305  
1306      >>> x = np.arange(20).reshape(5, 4)
1307      >>> row, col = np.indices((2, 3))
1308      >>> x[row, col]
1309      array([[0, 1, 2],
1310             [4, 5, 6]])
1311  
1312      Note that it would be more straightforward in the above example to
1313      extract the required elements directly with ``x[:2, :3]``.
1314  
1315      If sparse is set to true, the grid will be returned in a sparse
1316      representation.
1317  
1318      >>> i, j = np.indices((2, 3), sparse=True)
1319      >>> i.shape
1320      (2, 1)
1321      >>> j.shape
1322      (1, 3)
1323      >>> i        # row indices
1324      array([[0],
1325             [1]])
1326      >>> j        # column indices
1327      array([[0, 1, 2]])
1328  
1329      )rr�Nr)r�r�r�	enumerater
r�)	�
1330  dimensionsr�sparse�Nr�r��i�dim�idxrxrxryr^�sU �
1331  r^�rr�cKr�r{rx)�functionr�rr��kwargsrxrxry�_fromfunction_dispatcherr�r"cKs:|durt||f||d�|��St||d�}||i|��S)a�
1332      Construct an array by executing a function over each coordinate.
1333  
1334      The resulting array therefore has a value ``fn(x, y, z)`` at
1335      coordinate ``(x, y, z)``.
1336  
1337      Parameters
1338      ----------
1339      function : callable
1340          The function is called with N parameters, where N is the rank of
1341          `shape`.  Each parameter represents the coordinates of the array
1342          varying along a specific axis.  For example, if `shape`
1343          were ``(2, 2)``, then the parameters would be
1344          ``array([[0, 0], [1, 1]])`` and ``array([[0, 1], [0, 1]])``
1345      shape : (N,) tuple of ints
1346          Shape of the output array, which also determines the shape of
1347          the coordinate arrays passed to `function`.
1348      dtype : data-type, optional
1349          Data-type of the coordinate arrays passed to `function`.
1350          By default, `dtype` is float.
1351      ${ARRAY_FUNCTION_LIKE}
1352  
1353          .. versionadded:: 1.20.0
1354  
1355      Returns
1356      -------
1357      fromfunction : any
1358          The result of the call to `function` is passed back directly.
1359          Therefore the shape of `fromfunction` is completely determined by
1360          `function`.  If `function` returns a scalar value, the shape of
1361          `fromfunction` would not match the `shape` parameter.
1362  
1363      See Also
1364      --------
1365      indices, meshgrid
1366  
1367      Notes
1368      -----
1369      Keywords other than `dtype` and `like` are passed to `function`.
1370  
1371      Examples
1372      --------
1373      >>> np.fromfunction(lambda i, j: i, (2, 2), dtype=float)
1374      array([[0., 0.],
1375             [1., 1.]])
1376             
1377      >>> np.fromfunction(lambda i, j: j, (2, 2), dtype=float)    
1378      array([[0., 1.],
1379             [0., 1.]])
1380             
1381      >>> np.fromfunction(lambda i, j: i == j, (3, 3), dtype=int)
1382      array([[ True, False, False],
1383             [False,  True, False],
1384             [False, False,  True]])
1385  
1386      >>> np.fromfunction(lambda i, j: i + j, (3, 3), dtype=int)
1387      array([[0, 1, 2],
1388             [1, 2, 3],
1389             [2, 3, 4]])
1390  
1391      Nrr�)�_fromfunction_with_liker^)r r�rr�r!�argsrxrxryr_s@r_cCst||d�j||d�S)Nr�)r~)rr�)�bufrr�r~rxrxry�_frombufferRsr&cCs"t|t�pt|�tvpt|tj�S)a�
1392      Returns True if the type of `element` is a scalar type.
1393  
1394      Parameters
1395      ----------
1396      element : any
1397          Input argument, can be of any type and shape.
1398  
1399      Returns
1400      -------
1401      val : bool
1402          True if `element` is a scalar type, False if it is not.
1403  
1404      See Also
1405      --------
1406      ndim : Get the number of dimensions of an array
1407  
1408      Notes
1409      -----
1410      If you need a stricter way to identify a *numerical* scalar, use
1411      ``isinstance(x, numbers.Number)``, as that returns ``False`` for most
1412      non-numerical elements such as strings.
1413  
1414      In most cases ``np.ndim(x) == 0`` should be used instead of this function,
1415      as that will also return true for 0d arrays. This is how numpy overloads
1416      functions in the style of the ``dx`` arguments to `gradient` and the ``bins``
1417      argument to `histogram`. Some key differences:
1418  
1419      +--------------------------------------+---------------+-------------------+
1420      | x                                    |``isscalar(x)``|``np.ndim(x) == 0``|
1421      +======================================+===============+===================+
1422      | PEP 3141 numeric objects (including  | ``True``      | ``True``          |
1423      | builtins)                            |               |                   |
1424      +--------------------------------------+---------------+-------------------+
1425      | builtin string and buffer objects    | ``True``      | ``True``          |
1426      +--------------------------------------+---------------+-------------------+
1427      | other builtin objects, like          | ``False``     | ``True``          |
1428      | `pathlib.Path`, `Exception`,         |               |                   |
1429      | the result of `re.compile`           |               |                   |
1430      +--------------------------------------+---------------+-------------------+
1431      | third-party objects like             | ``False``     | ``True``          |
1432      | `matplotlib.figure.Figure`           |               |                   |
1433      +--------------------------------------+---------------+-------------------+
1434      | zero-dimensional numpy arrays        | ``False``     | ``True``          |
1435      +--------------------------------------+---------------+-------------------+
1436      | other numpy arrays                   | ``False``     | ``False``         |
1437      +--------------------------------------+---------------+-------------------+
1438      | `list`, `tuple`, and other sequence  | ``False``     | ``False``         |
1439      | objects                              |               |                   |
1440      +--------------------------------------+---------------+-------------------+
1441  
1442      Examples
1443      --------
1444      >>> np.isscalar(3.1)
1445      True
1446      >>> np.isscalar(np.array(3.1))
1447      False
1448      >>> np.isscalar([3.1])
1449      False
1450      >>> np.isscalar(False)
1451      True
1452      >>> np.isscalar('numpy')
1453      True
1454  
1455      NumPy supports PEP 3141 numbers:
1456  
1457      >>> from fractions import Fraction
1458      >>> np.isscalar(Fraction(5, 17))
1459      True
1460      >>> from numbers import Number
1461      >>> np.isscalar(Number())
1462      True
1463  
1464      )�
1465  isinstance�genericr��
1466  ScalarType�numbers�Number)�elementrxrxryraVs
1467  
1468  L
1469  �
1470  �racCs
1471  dd�}t�|�}|dkrd|pdS|dkr8t|�dd�}t|�}|dur)|nt||�}|||�|�|�S|durGdt|�dd�Stt|�dd��}d|d|kr_|d8}d|d|}t|�dd�}t|�}t||�}|||�d	|||S)
1472  a�
1473      Return the binary representation of the input number as a string.
1474  
1475      For negative numbers, if width is not given, a minus sign is added to the
1476      front. If width is given, the two's complement of the number is
1477      returned, with respect to that width.
1478  
1479      In a two's-complement system negative numbers are represented by the two's
1480      complement of the absolute value. This is the most common method of
1481      representing signed integers on computers [1]_. A N-bit two's-complement
1482      system can represent every integer in the range
1483      :math:`-2^{N-1}` to :math:`+2^{N-1}-1`.
1484  
1485      Parameters
1486      ----------
1487      num : int
1488          Only an integer decimal number can be used.
1489      width : int, optional
1490          The length of the returned string if `num` is positive, or the length
1491          of the two's complement if `num` is negative, provided that `width` is
1492          at least a sufficient number of bits for `num` to be represented in the
1493          designated form.
1494  
1495          If the `width` value is insufficient, it will be ignored, and `num` will
1496          be returned in binary (`num` > 0) or two's complement (`num` < 0) form
1497          with its width equal to the minimum number of bits needed to represent
1498          the number in the designated form. This behavior is deprecated and will
1499          later raise an error.
1500  
1501          .. deprecated:: 1.12.0
1502  
1503      Returns
1504      -------
1505      bin : str
1506          Binary representation of `num` or two's complement of `num`.
1507  
1508      See Also
1509      --------
1510      base_repr: Return a string representation of a number in the given base
1511                 system.
1512      bin: Python's built-in binary representation generator of an integer.
1513  
1514      Notes
1515      -----
1516      `binary_repr` is equivalent to using `base_repr` with base 2, but about 25x
1517      faster.
1518  
1519      References
1520      ----------
1521      .. [1] Wikipedia, "Two's complement",
1522          https://en.wikipedia.org/wiki/Two's_complement
1523  
1524      Examples
1525      --------
1526      >>> np.binary_repr(3)
1527      '11'
1528      >>> np.binary_repr(-3)
1529      '-11'
1530      >>> np.binary_repr(3, width=4)
1531      '0011'
1532  
1533      The two's complement is returned when the input number is negative and
1534      width is specified:
1535  
1536      >>> np.binary_repr(-3, width=3)
1537      '101'
1538      >>> np.binary_repr(-3, width=5)
1539      '11101'
1540  
1541      cSs,|dur||krtjdtdd�dSdSdS)NzQInsufficient bit width provided. This behavior will raise an error in the future.r)�
1542  stacklevel)�warnings�warn�DeprecationWarning)�width�binwidthrxrxry�warn_if_insufficient�s
1543  ��z)binary_repr.<locals>.warn_if_insufficientr�0rr�N�-�1)r�r��binr��max�zfill)�numr1r3�binaryr2ZoutwidthZposwidthZtwocomprxrxryrb�s.H
1544  	�
1545  
1546  
1547  
1548  rbcCs�d}|t|�krtd��|dkrtd��t|�}g}|r+|�|||�||}|s|r4|�d|�|dkr=|�d�d�t|pCd��S)	aZ
1549      Return a string representation of a number in the given base system.
1550  
1551      Parameters
1552      ----------
1553      number : int
1554          The value to convert. Positive and negative values are handled.
1555      base : int, optional
1556          Convert `number` to the `base` number system. The valid range is 2-36,
1557          the default value is 2.
1558      padding : int, optional
1559          Number of zeros padded on the left. Default is 0 (no padding).
1560  
1561      Returns
1562      -------
1563      out : str
1564          String representation of `number` in `base` system.
1565  
1566      See Also
1567      --------
1568      binary_repr : Faster version of `base_repr` for base 2.
1569  
1570      Examples
1571      --------
1572      >>> np.base_repr(5)
1573      '101'
1574      >>> np.base_repr(6, 5)
1575      '11'
1576      >>> np.base_repr(7, base=5, padding=3)
1577      '00012'
1578  
1579      >>> np.base_repr(10, base=16)
1580      'A'
1581      >>> np.base_repr(32, base=16)
1582      '20'
1583  
1584      Z$0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZz/Bases greater than 36 not handled in base_repr.r�z+Bases less than 2 not handled in base_repr.r4rr5�)r�r��abs�append�join�reversed)�number�base�padding�digitsr:r�rxrxryrcs '�
1585  rccs8t|�}|j��dur
�S��fdd�|jD�}t|�S)Ncsg|]}t�|d���qSr�)�_maketup)r��name��fields�valrxryr�^sz_maketup.<locals>.<listcomp>)rrH�namesr�)�descrrI�dtr�rxrGryrEWsrEcCs|fSr{rx)r�rr�rxrxry�_identity_dispatcherbr�rMcCs0|durt|||d�Sddlm}||||d�S)az
1586      Return the identity array.
1587  
1588      The identity array is a square array with ones on
1589      the main diagonal.
1590  
1591      Parameters
1592      ----------
1593      n : int
1594          Number of rows (and columns) in `n` x `n` output.
1595      dtype : data-type, optional
1596          Data-type of the output.  Defaults to ``float``.
1597      ${ARRAY_FUNCTION_LIKE}
1598  
1599          .. versionadded:: 1.20.0
1600  
1601      Returns
1602      -------
1603      out : ndarray
1604          `n` x `n` array with its main diagonal set to one,
1605          and all other elements 0.
1606  
1607      Examples
1608      --------
1609      >>> np.identity(3)
1610      array([[1.,  0.,  0.],
1611             [0.,  1.,  0.],
1612             [0.,  0.,  1.]])
1613  
1614      Nrr)�eye)�_identity_with_likerJrN)r�rr�rNrxrxryrefs!recCr�r{rx�r}r��rtol�atol�	equal_nanrxrxry�_allclose_dispatcher�r�rT��h㈵��>�:�0�yE>cCstt|||||d��}t|�S)aw
1615      Returns True if two arrays are element-wise equal within a tolerance.
1616  
1617      The tolerance values are positive, typically very small numbers.  The
1618      relative difference (`rtol` * abs(`b`)) and the absolute difference
1619      `atol` are added together to compare against the absolute difference
1620      between `a` and `b`.
1621  
1622      NaNs are treated as equal if they are in the same place and if
1623      ``equal_nan=True``.  Infs are treated as equal if they are in the same
1624      place and of the same sign in both arrays.
1625  
1626      Parameters
1627      ----------
1628      a, b : array_like
1629          Input arrays to compare.
1630      rtol : float
1631          The relative tolerance parameter (see Notes).
1632      atol : float
1633          The absolute tolerance parameter (see Notes).
1634      equal_nan : bool
1635          Whether to compare NaN's as equal.  If True, NaN's in `a` will be
1636          considered equal to NaN's in `b` in the output array.
1637  
1638          .. versionadded:: 1.10.0
1639  
1640      Returns
1641      -------
1642      allclose : bool
1643          Returns True if the two arrays are equal within the given
1644          tolerance; False otherwise.
1645  
1646      See Also
1647      --------
1648      isclose, all, any, equal
1649  
1650      Notes
1651      -----
1652      If the following equation is element-wise True, then allclose returns
1653      True.
1654  
1655       absolute(`a` - `b`) <= (`atol` + `rtol` * absolute(`b`))
1656  
1657      The above equation is not symmetric in `a` and `b`, so that
1658      ``allclose(a, b)`` might be different from ``allclose(b, a)`` in
1659      some rare cases.
1660  
1661      The comparison of `a` and `b` uses standard broadcasting, which
1662      means that `a` and `b` need not have the same shape in order for
1663      ``allclose(a, b)`` to evaluate to True.  The same is true for
1664      `equal` but not `array_equal`.
1665  
1666      `allclose` is not defined for non-numeric data types.
1667      `bool` is considered a numeric data-type for this purpose.
1668  
1669      Examples
1670      --------
1671      >>> np.allclose([1e10,1e-7], [1.00001e10,1e-8])
1672      False
1673      >>> np.allclose([1e10,1e-8], [1.00001e10,1e-9])
1674      True
1675      >>> np.allclose([1e10,1e-8], [1.0001e10,1e-9])
1676      False
1677      >>> np.allclose([1.0, np.nan], [1.0, np.nan])
1678      False
1679      >>> np.allclose([1.0, np.nan], [1.0, np.nan], equal_nan=True)
1680      True
1681  
1682      )rQrRrS)�allr`�bool)r}r�rQrRrSr�rxrxryrf�sGrfcCr�r{rxrPrxrxry�_isclose_dispatcher�r�rYcCs�dd�}t|�}t|�}|jjdkrt�|d�}t||d�}t|�}	t|�}
1683  t|	�r5t|
1684  �r5|||||�S|	|
1685  @}t|dd�}|t|�}|t|�}|||||||�||<||||k||<|rut	|�t	|�@}
|
|
||
<|dS)	aW
1686      Returns a boolean array where two arrays are element-wise equal within a
1687      tolerance.
1688  
1689      The tolerance values are positive, typically very small numbers.  The
1690      relative difference (`rtol` * abs(`b`)) and the absolute difference
1691      `atol` are added together to compare against the absolute difference
1692      between `a` and `b`.
1693  
1694      .. warning:: The default `atol` is not appropriate for comparing numbers
1695                   that are much smaller than one (see Notes).
1696  
1697      Parameters
1698      ----------
1699      a, b : array_like
1700          Input arrays to compare.
1701      rtol : float
1702          The relative tolerance parameter (see Notes).
1703      atol : float
1704          The absolute tolerance parameter (see Notes).
1705      equal_nan : bool
1706          Whether to compare NaN's as equal.  If True, NaN's in `a` will be
1707          considered equal to NaN's in `b` in the output array.
1708  
1709      Returns
1710      -------
1711      y : array_like
1712          Returns a boolean array of where `a` and `b` are equal within the
1713          given tolerance. If both `a` and `b` are scalars, returns a single
1714          boolean value.
1715  
1716      See Also
1717      --------
1718      allclose
1719      math.isclose
1720  
1721      Notes
1722      -----
1723      .. versionadded:: 1.7.0
1724  
1725      For finite values, isclose uses the following equation to test whether
1726      two floating point values are equivalent.
1727  
1728       absolute(`a` - `b`) <= (`atol` + `rtol` * absolute(`b`))
1729  
1730      Unlike the built-in `math.isclose`, the above equation is not symmetric
1731      in `a` and `b` -- it assumes `b` is the reference value -- so that
1732      `isclose(a, b)` might be different from `isclose(b, a)`. Furthermore,
1733      the default value of atol is not zero, and is used to determine what
1734      small values should be considered close to zero. The default value is
1735      appropriate for expected values of order unity: if the expected values
1736      are significantly smaller than one, it can result in false positives.
1737      `atol` should be carefully selected for the use case at hand. A zero value
1738      for `atol` will result in `False` if either `a` or `b` is zero.
1739  
1740      `isclose` is not defined for non-numeric data types.
1741      `bool` is considered a numeric data-type for this purpose.
1742  
1743      Examples
1744      --------
1745      >>> np.isclose([1e10,1e-7], [1.00001e10,1e-8])
1746      array([ True, False])
1747      >>> np.isclose([1e10,1e-8], [1.00001e10,1e-9])
1748      array([ True, True])
1749      >>> np.isclose([1e10,1e-8], [1.0001e10,1e-9])
1750      array([False,  True])
1751      >>> np.isclose([1.0, np.nan], [1.0, np.nan])
1752      array([ True, False])
1753      >>> np.isclose([1.0, np.nan], [1.0, np.nan], equal_nan=True)
1754      array([ True, True])
1755      >>> np.isclose([1e-8, 1e-7], [0.0, 0.0])
1756      array([ True, False])
1757      >>> np.isclose([1e-100, 1e-7], [0.0, 0.0], atol=0.0)
1758      array([False, False])
1759      >>> np.isclose([1e-10, 1e-10], [1e-20, 0.0])
1760      array([ True,  True])
1761      >>> np.isclose([1e-10, 1e-10], [1e-20, 0.999999e-10], atol=0.0)
1762      array([False,  True])
1763      c	Ss�tdd��2t��tt||�||t|��Wd�Wd�S1s*wYWd�dS1s:wYdS)N�ignore)�invalid)rHrI�
1764  less_equalr=)�x�yrRrQrxrxry�
1765  within_tol7	sR�zisclose.<locals>.within_tol�mg�?r�T)rrx)
1766  rr�kindrr,�isfiniterWrQrR�isnan)r}r�rQrRrSr_r]r^rLZxfinZyfin�finite�condZboth_nanrxrxryr`�s(Q	r`cCr�r{rx)rrrSrxrxry�_array_equal_dispatcherc	r�rfcCs�zt|�t|�}}Wn
1767  tyYdSw|j|jkrdS|s*tt||k����St|�t|�}}||k��s;dStt||||k����S)a�
1768      True if two arrays have the same shape and elements, False otherwise.
1769  
1770      Parameters
1771      ----------
1772      a1, a2 : array_like
1773          Input arrays.
1774      equal_nan : bool
1775          Whether to compare NaN's as equal. If the dtype of a1 and a2 is
1776          complex, values will be considered equal if either the real or the
1777          imaginary component of a given value is ``nan``.
1778  
1779          .. versionadded:: 1.19.0
1780  
1781      Returns
1782      -------
1783      b : bool
1784          Returns True if the arrays are equal.
1785  
1786      See Also
1787      --------
1788      allclose: Returns True if two arrays are element-wise equal within a
1789                tolerance.
1790      array_equiv: Returns True if input arrays are shape consistent and all
1791                   elements equal.
1792  
1793      Examples
1794      --------
1795      >>> np.array_equal([1, 2], [1, 2])
1796      True
1797      >>> np.array_equal(np.array([1, 2]), np.array([1, 2]))
1798      True
1799      >>> np.array_equal([1, 2], [1, 2, 3])
1800      False
1801      >>> np.array_equal([1, 2], [1, 4])
1802      False
1803      >>> a = np.array([1, np.nan])
1804      >>> np.array_equal(a, a)
1805      False
1806      >>> np.array_equal(a, a, equal_nan=True)
1807      True
1808  
1809      When ``equal_nan`` is True, complex values with nan components are
1810      considered equal if either the real *or* the imaginary components are nan.
1811  
1812      >>> a = np.array([1 + 1j])
1813      >>> b = a.copy()
1814      >>> a.real = np.nan
1815      >>> b.imag = np.nan
1816      >>> np.array_equal(a, b, equal_nan=True)
1817      True
1818      F)rr�r�rXrWrc)rrrSZa1nanZa2nanrxrxryr\g	s6� r\cCr�r{rx�rrrxrxry�_array_equiv_dispatcher�	r�rhcCsfzt|�t|�}}Wn
1819  tyYdSwzt�||�Wn
1820  ty(YdSwtt||k����S)a�
1821      Returns True if input arrays are shape consistent and all elements equal.
1822  
1823      Shape consistent means they are either the same shape, or one input array
1824      can be broadcasted to create the same shape as the other one.
1825  
1826      Parameters
1827      ----------
1828      a1, a2 : array_like
1829          Input arrays.
1830  
1831      Returns
1832      -------
1833      out : bool
1834          True if equivalent, False otherwise.
1835  
1836      Examples
1837      --------
1838      >>> np.array_equiv([1, 2], [1, 2])
1839      True
1840      >>> np.array_equiv([1, 2], [1, 3])
1841      False
1842  
1843      Showing the shape equivalence:
1844  
1845      >>> np.array_equiv([1, 2], [[1, 2], [1, 2]])
1846      True
1847      >>> np.array_equiv([1, 2], [[1, 2, 1, 2], [1, 2, 1, 2]])
1848      False
1849  
1850      >>> np.array_equiv([1, 2], [[1, 2], [1, 3]])
1851      False
1852  
1853      F)rr�rrrXrWrgrxrxryr]�	s$��r]cCs2tt�}t|d�}|D]}||vrt�|�qdS)N�__all__)r�ri�getattrr>)rK�existingZmallr}rxrxry�
1854  extend_all�	s
1855  
1856  ��rl)�*)�fromnumeric)�
1857  arrayprint)�_asarray)�
_ufunc_config)NNNN)Nr�TN)NN)Nr�r{)r�)rr)r�r�)NF)r�r�r�N)r�r)NNN)rUrVF)F)��	functoolsr�r��sysr.r*rJr�r<rrrrrrr	r
1858  rrr
rrrrrrrrrrrrrrrrrrr r!r"r#r$r%r&r'r(r)r*r+r,r-r.r/r0r1r2r3r4r5r6r7r8r9r:r;r<r=r>r?r@rArBrCrDrE�_exceptionsrFrGrqrHrIrpr�rMrL�partial�array_function_dispatchri�RuntimeWarningrqr�rQr�rdr�r�rRr�rrr�r�rsr�rNrPr�rOr�rgr�rSr�rTr�rUr�rZr�rVr�rWr�rrXr
1859  rY�	byteorderr[r�r^r"�floatr_r#r&rarbrcrErMrerOrTrfrYr`rfr\rhr]rhrirjrkrlrmrnrorlrnrorprxrxrxry�<module>s4� �
1860  D:��
1861  B9��
1862  EI
1863  C
1864  1
1865  
1866  (
1867  I
1868  b
1869  W
1870  A
1871  j
1872  Y;
1873  
1874  F
1875  JfE��
1876  Pr<&��
1877  
1878  J
1879  |F
1880  /