
    (ph>                     b   S SK r S SKrS SKrS SKJr  S SKJr  SSKJ	r	  SSKJ
r
  SSKJr  / SQr\S	S
\R                  S4S j5       r\S	\R                  S4S j5       rS r\    SS j5       r\  SS j5       r\   SS j5       r\  SS j5       r\  SSS.S jj5       r\  SS j5       rg)    N)normalize_axis_index)special   )_ni_support)	_nd_image)	docfiller)spline_filter1dspline_filtergeometric_transformmap_coordinatesaffine_transformshiftzoomrotate   mirrorc                    US:  d  US:  a  [        S5      e[        R                  " U 5      n [        R                  " U 5      n[        R
                  " X0US9nU(       aF  [        U R                  XUR                  U5        [        U R                  XUR                  U5        U$ US;   a  [        R                  " U 5      US'   U$ [        R                  " U5      n[        X R                  5      n[        R                  " XX#U5        U$ )ag  
Calculate a 1-D spline filter along the given axis.

The lines of the array along the given axis are filtered by a
spline filter. The order of the spline must be >= 2 and <= 5.

Parameters
----------
%(input)s
order : int, optional
    The order of the spline, default is 3.
axis : int, optional
    The axis along which the spline filter is applied. Default is the last
    axis.
output : ndarray or dtype, optional
    The array in which to place the output, or the dtype of the returned
    array. Default is ``numpy.float64``.
%(mode_interp_mirror)s

Returns
-------
spline_filter1d : ndarray
    The filtered input.

See Also
--------
spline_filter : Multidimensional spline filter.

Notes
-----
All of the interpolation functions in `ndimage` do spline interpolation of
the input image. If using B-splines of `order > 1`, the input image
values have to be converted to B-spline coefficients first, which is
done by applying this 1-D filter sequentially along all
axes of the input. All functions that require B-spline coefficients
will automatically filter their inputs, a behavior controllable with
the `prefilter` keyword argument. For functions that accept a `mode`
parameter, the result will only be correct if it matches the `mode`
used when filtering.

For complex-valued `input`, this function processes the real and imaginary
components independently.

.. versionadded:: 1.6.0
    Complex-valued support added.

Examples
--------
We can filter an image using 1-D spline along the given axis:

>>> from scipy.ndimage import spline_filter1d
>>> import numpy as np
>>> import matplotlib.pyplot as plt
>>> orig_img = np.eye(20)  # create an image
>>> orig_img[10, :] = 1.0
>>> sp_filter_axis_0 = spline_filter1d(orig_img, axis=0)
>>> sp_filter_axis_1 = spline_filter1d(orig_img, axis=1)
>>> f, ax = plt.subplots(1, 3, sharex=True)
>>> for ind, data in enumerate([[orig_img, "original image"],
...             [sp_filter_axis_0, "spline filter (axis=0)"],
...             [sp_filter_axis_1, "spline filter (axis=1)"]]):
...     ax[ind].imshow(data[0], cmap='gray_r')
...     ax[ind].set_title(data[1])
>>> plt.tight_layout()
>>> plt.show()

r      spline order not supportedcomplex_outputr   r   .)RuntimeErrornpasarrayiscomplexobjr   _get_outputr	   realimagarray_extend_mode_to_coder   ndimr   )inputorderaxisoutputmoder   s         O/var/www/html/venv/lib/python3.13/site-packages/scipy/ndimage/_interpolation.pyr	   r	   /   s    L qyEAI788JJuE__U+N$$V4BDF

EdC

EdChhuos
 M //5#D**5!!%dCM    c           	         US:  d  US:  a  [        S5      e[        R                  " U 5      n [        R                  " U 5      n[        R
                  " X US9nU(       aD  [        U R                  XR                  U5        [        U R                  XR                  U5        U$ US;  a;  U R                  S:  a+  [        U R                  5       H  n[        XXRUS9  Un M     U$ U S   US'   U$ )	a  
Multidimensional spline filter.

Parameters
----------
%(input)s
order : int, optional
    The order of the spline, default is 3.
output : ndarray or dtype, optional
    The array in which to place the output, or the dtype of the returned
    array. Default is ``numpy.float64``.
%(mode_interp_mirror)s

Returns
-------
spline_filter : ndarray
    Filtered array. Has the same shape as `input`.

See Also
--------
spline_filter1d : Calculate a 1-D spline filter along the given axis.

Notes
-----
The multidimensional filter is implemented as a sequence of
1-D spline filters. The intermediate arrays are stored
in the same data type as the output. Therefore, for output types
with a limited precision, the results may be imprecise because
intermediate results may be stored with insufficient precision.

For complex-valued `input`, this function processes the real and imaginary
components independently.

.. versionadded:: 1.6.0
    Complex-valued support added.

Examples
--------
We can filter an image using multidimensional splines:

>>> from scipy.ndimage import spline_filter
>>> import numpy as np
>>> import matplotlib.pyplot as plt
>>> orig_img = np.eye(20)  # create an image
>>> orig_img[10, :] = 1.0
>>> sp_filter = spline_filter(orig_img, order=3)
>>> f, ax = plt.subplots(1, 2, sharex=True)
>>> for ind, data in enumerate([[orig_img, "original image"],
...                             [sp_filter, "spline filter"]]):
...     ax[ind].imshow(data[0], cmap='gray_r')
...     ax[ind].set_title(data[1])
>>> plt.tight_layout()
>>> plt.show()

   r   r   r   r   r   r'   r(   .)r   r   r   r   r   r   r
   r   r    r#   ranger	   )r$   r%   r'   r(   r   r&   s         r)   r
   r
      s    r qyEAI788JJuE__U+N$$V4BDFejj%d;ejj%d;FuzzA~%**%DE$DIE &
 M CjsMr*   c                     US;   a@  SnUS:X  a  [         R                  " XSUS9nXC4$ US:X  a  [         R                  " XSS9nWU4$ S	nU nXC4$ )
N)nearestgrid-constant   r1   constant)r(   constant_valuesr0   edge)r(   r   )r   pad)r$   r(   cvalnpadpaddeds        r)   _prepad_for_spline_filterr:      sq    ++?"VVEj/35F < YVVEf5F 4< <r*   c
                    U	c  0 n	US:  d  US:  a  [        S5      e[        R                  " U 5      n Uc  U R                  nU R                  S:  d  [        U5      S:  a  [        S5      e[        R                  " U 5      n
[        R                  " X0UU
S9nU
(       a  [        XEUUUU	S9n[        U R                  U4UR                  [        R                  " U5      S	.UD6  [        U R                  U4UR                  [        R                  " U5      S	.UD6  U$ U(       a.  US:  a(  [        XU5      u  p[        X[        R                  US
9nOSnU n[        R                   " U5      n["        R                  " XSSSUXEXmUU	5        U$ )a_  
Apply an arbitrary geometric transform.

The given mapping function is used to find, for each point in the
output, the corresponding coordinates in the input. The value of the
input at those coordinates is determined by spline interpolation of
the requested order.

Parameters
----------
%(input)s
mapping : {callable, scipy.LowLevelCallable}
    A callable object that accepts a tuple of length equal to the output
    array rank, and returns the corresponding input coordinates as a tuple
    of length equal to the input array rank.
output_shape : tuple of ints, optional
    Shape tuple.
%(output)s
order : int, optional
    The order of the spline interpolation, default is 3.
    The order has to be in the range 0-5.
%(mode_interp_constant)s
%(cval)s
%(prefilter)s
extra_arguments : tuple, optional
    Extra arguments passed to `mapping`.
extra_keywords : dict, optional
    Extra keywords passed to `mapping`.

Returns
-------
output : ndarray
    The filtered input.

See Also
--------
map_coordinates, affine_transform, spline_filter1d


Notes
-----
This function also accepts low-level callback functions with one
the following signatures and wrapped in `scipy.LowLevelCallable`:

.. code:: c

   int mapping(npy_intp *output_coordinates, double *input_coordinates,
               int output_rank, int input_rank, void *user_data)
   int mapping(intptr_t *output_coordinates, double *input_coordinates,
               int output_rank, int input_rank, void *user_data)

The calling function iterates over the elements of the output array,
calling the callback function at each element. The coordinates of the
current output element are passed through ``output_coordinates``. The
callback function must return the coordinates at which the input must
be interpolated in ``input_coordinates``. The rank of the input and
output arrays are given by ``input_rank`` and ``output_rank``
respectively. ``user_data`` is the data pointer provided
to `scipy.LowLevelCallable` as-is.

The callback function must return an integer error status that is zero
if something went wrong and one otherwise. If an error occurs, you should
normally set the Python error status with an informative message
before returning, otherwise a default error message is set by the
calling function.

In addition, some other low-level function pointer specifications
are accepted, but these are for backward compatibility only and should
not be used in new code.

For complex-valued `input`, this function transforms the real and imaginary
components independently.

.. versionadded:: 1.6.0
    Complex-valued support added.

Examples
--------
>>> import numpy as np
>>> from scipy.ndimage import geometric_transform
>>> a = np.arange(12.).reshape((4, 3))
>>> def shift_func(output_coords):
...     return (output_coords[0] - 0.5, output_coords[1] - 0.5)
...
>>> geometric_transform(a, shift_func)
array([[ 0.   ,  0.   ,  0.   ],
       [ 0.   ,  1.362,  2.738],
       [ 0.   ,  4.812,  6.187],
       [ 0.   ,  8.263,  9.637]])

>>> b = [1, 2, 3, 4, 5]
>>> def shift_func(output_coords):
...     return (output_coords[0] - 3,)
...
>>> geometric_transform(b, shift_func, mode='constant')
array([0, 0, 0, 1, 2])
>>> geometric_transform(b, shift_func, mode='nearest')
array([1, 1, 1, 1, 2])
>>> geometric_transform(b, shift_func, mode='reflect')
array([3, 2, 1, 1, 2])
>>> geometric_transform(b, shift_func, mode='wrap')
array([2, 3, 4, 1, 2])

Nr   r   r   r   !input and output rank must be > 0shaper   )r%   r(   	prefilteroutput_shapeextra_argumentsextra_keywordsr'   r7   r-   )r   r   r   r>   r#   lenr   r   r   dictr   r   r    r:   r
   float64r"   r   )r$   mappingr@   r'   r%   r(   r7   r?   rA   rB   r   kwargsr9   r8   filtereds                  r)   r   r      s}   Z qyEAI788JJuE{{zzA~\*Q.>??__U+N$$V,4BDFE	#/&5%35 	EJJ 	:!#	:28	:EJJ 	:!#	:28	:UQY0dC rzz&*, ++D1D!!(T4v"'t?"02 Mr*   c                    US:  d  US:  a  [        S5      e[        R                  " U 5      n [        R                  " U5      n[        R                  " U5      (       a  [	        S5      eUR
                  SS nU R                  S:  d  [        U5      S:  a  [        S5      eUR
                  S   U R                  :w  a  [        S5      e[        R                  " U 5      n[        R                  " X UUS	9nU(       a|  [        X4US
9n	[        U R                  U4UR                  [        R                  " U5      S.U	D6  [        U R                  U4UR                  [        R                  " U5      S.U	D6  U$ U(       a.  US:  a(  [        XU5      u  p[        X[        R                   US9nOSnU n[        R"                  " U5      n[$        R&                  " USUSSX#XEUSS5        U$ )av  
Map the input array to new coordinates by interpolation.

The array of coordinates is used to find, for each point in the output,
the corresponding coordinates in the input. The value of the input at
those coordinates is determined by spline interpolation of the
requested order.

The shape of the output is derived from that of the coordinate
array by dropping the first axis. The values of the array along
the first axis are the coordinates in the input array at which the
output value is found.

Parameters
----------
%(input)s
coordinates : array_like
    The coordinates at which `input` is evaluated.
%(output)s
order : int, optional
    The order of the spline interpolation, default is 3.
    The order has to be in the range 0-5.
%(mode_interp_constant)s
%(cval)s
%(prefilter)s

Returns
-------
map_coordinates : ndarray
    The result of transforming the input. The shape of the output is
    derived from that of `coordinates` by dropping the first axis.

See Also
--------
spline_filter, geometric_transform, scipy.interpolate

Notes
-----
For complex-valued `input`, this function maps the real and imaginary
components independently.

.. versionadded:: 1.6.0
    Complex-valued support added.

Examples
--------
>>> from scipy import ndimage
>>> import numpy as np
>>> a = np.arange(12.).reshape((4, 3))
>>> a
array([[  0.,   1.,   2.],
       [  3.,   4.,   5.],
       [  6.,   7.,   8.],
       [  9.,  10.,  11.]])
>>> ndimage.map_coordinates(a, [[0.5, 2], [0.5, 1]], order=1)
array([ 2.,  7.])

Above, the interpolated value of a[0.5, 0.5] gives output[0], while
a[2, 1] is output[1].

>>> inds = np.array([[0.5, 2], [0.5, 4]])
>>> ndimage.map_coordinates(a, inds, order=1, cval=-33.3)
array([  2. , -33.3])
>>> ndimage.map_coordinates(a, inds, order=1, mode='nearest')
array([ 2.,  8.])
>>> ndimage.map_coordinates(a, inds, order=1, cval=0, output=bool)
array([ True, False], dtype=bool)

r   r   r   zComplex type not supportedr   Nr<   z"invalid shape for coordinate arrayr=   r%   r(   r?   rC   r-   )r   r   r   r   	TypeErrorr>   r#   rD   r   r   rE   r   r   r    r:   r
   rF   r"   r   r   )r$   coordinatesr'   r%   r(   r7   r?   r@   r   rH   r9   r8   rI   s                r)   r   r   u  s   P qyEAI788JJuE**[)K	{##455$$QR(LzzA~\*Q.>??uzz)?@@__U+N$$V,4BDFE	B

K 	6WWT]	6.4	6

K 	6WWT]	6.4	6UQY0dC rzzM++D1D!!(D+tT"(T4OMr*   c	                 	   US:  d  US:  a  [        S5      e[        R                  " U 5      n Uc8  [        U[        R                  5      (       a  UR
                  nOU R
                  nU R                  S:  d  [        U5      S:  a  [        S5      e[        R                  " U 5      n	[        R                  " X@UU	S9nU	(       a}  [        X#UXhS9n
[        U R                  U4UR                  [        R                  " U5      S	.U
D6  [        U R                  U4UR                  [        R                  " U5      S	.U
D6  U$ U(       a.  US:  a(  [        XU5      u  p[!        X[        R"                  US
9nOSnU n[        R$                  " U5      n[        R                  " U[        R"                  S9nUR                  S;  d  UR
                  S   S:  a  [        S5      eUR                  S:X  Ga  UR
                  S   U R                  S-   :X  a  UR
                  S   U R                  U R                  S-   4;   a  UR
                  S   U R                  S-   :X  ah  S/U R                  -  S/-   n[        R&                  " XR                     U:H  5      (       d*  SUR
                   SU R
                   SU 3n[)        U5      eUSU R                  2U R                  4   nUSU R                  2SU R                  24   nUR
                  S   U R                  :w  a  [        S5      eUR                  S:X  a(  UR
                  S   UR                  :w  a  [        S5      eUR*                  R,                  (       d  UR/                  5       n[        R0                  " X R                  5      n[        R                  " U[        R"                  S9nUR                  S:w  d  UR
                  S   S:  a  [        S5      eUR*                  R,                  (       d  UR/                  5       nUR                  S:X  a4  [2        R4                  " SSS9  [6        R8                  " XX!-  XEXgUS5	        U$ [6        R:                  " USSXXEXgUSS5        U$ )a  
Apply an affine transformation.

Given an output image pixel index vector ``o``, the pixel value
is determined from the input image at position
``np.dot(matrix, o) + offset``.

This does 'pull' (or 'backward') resampling, transforming the output space
to the input to locate data. Affine transformations are often described in
the 'push' (or 'forward') direction, transforming input to output. If you
have a matrix for the 'push' transformation, use its inverse
(:func:`numpy.linalg.inv`) in this function.

Parameters
----------
%(input)s
matrix : ndarray
    The inverse coordinate transformation matrix, mapping output
    coordinates to input coordinates. If ``ndim`` is the number of
    dimensions of ``input``, the given matrix must have one of the
    following shapes:

        - ``(ndim, ndim)``: the linear transformation matrix for each
          output coordinate.
        - ``(ndim,)``: assume that the 2-D transformation matrix is
          diagonal, with the diagonal specified by the given value. A more
          efficient algorithm is then used that exploits the separability
          of the problem.
        - ``(ndim + 1, ndim + 1)``: assume that the transformation is
          specified using homogeneous coordinates [1]_. In this case, any
          value passed to ``offset`` is ignored.
        - ``(ndim, ndim + 1)``: as above, but the bottom row of a
          homogeneous transformation matrix is always ``[0, 0, ..., 1]``,
          and may be omitted.

offset : float or sequence, optional
    The offset into the array where the transform is applied. If a float,
    `offset` is the same for each axis. If a sequence, `offset` should
    contain one value for each axis.
output_shape : tuple of ints, optional
    Shape tuple.
%(output)s
order : int, optional
    The order of the spline interpolation, default is 3.
    The order has to be in the range 0-5.
%(mode_interp_constant)s
%(cval)s
%(prefilter)s

Returns
-------
affine_transform : ndarray
    The transformed input.

Notes
-----
The given matrix and offset are used to find for each point in the
output the corresponding coordinates in the input by an affine
transformation. The value of the input at those coordinates is
determined by spline interpolation of the requested order. Points
outside the boundaries of the input are filled according to the given
mode.

.. versionchanged:: 0.18.0
    Previously, the exact interpretation of the affine transformation
    depended on whether the matrix was supplied as a 1-D or a
    2-D array. If a 1-D array was supplied
    to the matrix parameter, the output pixel value at index ``o``
    was determined from the input image at position
    ``matrix * (o + offset)``.

For complex-valued `input`, this function transforms the real and imaginary
components independently.

.. versionadded:: 1.6.0
    Complex-valued support added.

References
----------
.. [1] https://en.wikipedia.org/wiki/Homogeneous_coordinates
r   r   r   Nr   r<   r=   )offsetr@   r%   r(   r?   rC   r-   dtype)r   r,   z no proper affine matrix providedr,   z6Expected homogeneous transformation matrix with shape z for image shape z", but bottom row was not equal to z&affine matrix has wrong number of rowsz)affine matrix has wrong number of columnszno proper offset providedzpThe behavior of affine_transform with a 1-D array supplied for the matrix parameter has changed in SciPy 0.18.0.
stacklevelF)r   r   r   
isinstancendarrayr>   r#   rD   r   r   r   rE   r   r   r    r:   r
   rF   r"   all
ValueErrorflags
contiguouscopy_normalize_sequencewarningswarnr   
zoom_shiftr   )r$   matrixrO   r@   r'   r%   r(   r7   r?   r   rH   r9   r8   rI   exptdmsgs                   r)   r   r     s   j qyEAI788JJuEfbjj))!<<L ;;LzzA~\*Q.>??__U+N$$V,4BDFVe6V 	7FKK ggdm	7/5	7V 	7FKK ggdm	7/5	7UQY0dC rzzM++D1DZZbjj1F{{& FLLOa$7=>>qV\\!_

Q>\\!_UZZ!^ <<<<?ejj1n,C%**$s*E66&,566  &~->u{{m L::?B !o%UZZ/0[ejj[01||A%**$CDD{{aFLLOv{{:FGG<<"",,VZZ@FZZbjj1F{{a6<<?Q.677<<""{{a 		
 	Xv}f!u	6 M 	%%hdF&,Tt&*	, Mr*   c                    US:  d  US:  a  [        S5      e[        R                  " U 5      n U R                  S:  a  [        S5      e[        R                  " U 5      n[
        R                  " X US9nU(       a|  SSKJn  [        X4US9n	U" U R                  U4UR                  [        R                  " U5      S	.U	D6  U" U R                  U4UR                  [        R                  " U5      S	.U	D6  U$ U(       a.  US:  a(  [        XU5      u  p[        X[        R                  US
9nOSnU n[
        R                  " U5      n[
        R                   " XR                  5      nU Vs/ s H  o* PM     nn[        R                  " U[        R                  S9nUR"                  R$                  (       d  UR'                  5       n[(        R*                  " USXX4UUS5	        U$ s  snf )a  
Shift an array.

The array is shifted using spline interpolation of the requested order.
Points outside the boundaries of the input are filled according to the
given mode.

Parameters
----------
%(input)s
shift : float or sequence
    The shift along the axes. If a float, `shift` is the same for each
    axis. If a sequence, `shift` should contain one value for each axis.
%(output)s
order : int, optional
    The order of the spline interpolation, default is 3.
    The order has to be in the range 0-5.
%(mode_interp_constant)s
%(cval)s
%(prefilter)s

Returns
-------
shift : ndarray
    The shifted input.

See Also
--------
affine_transform : Affine transformations

Notes
-----
For complex-valued `input`, this function shifts the real and imaginary
components independently.

.. versionadded:: 1.6.0
    Complex-valued support added.

Examples
--------
Import the necessary modules and an exemplary image.

>>> from scipy.ndimage import shift
>>> import matplotlib.pyplot as plt
>>> from scipy import datasets
>>> image = datasets.ascent()

Shift the image vertically by 20 pixels.

>>> image_shifted_vertically = shift(image, (20, 0))

Shift the image vertically by -200 pixels and horizontally by 100 pixels.

>>> image_shifted_both_directions = shift(image, (-200, 100))

Plot the original and the shifted images.

>>> fig, axes = plt.subplots(3, 1, figsize=(4, 12))
>>> plt.gray()  # show the filtered result in grayscale
>>> top, middle, bottom = axes
>>> for ax in axes:
...     ax.set_axis_off()  # remove coordinate system
>>> top.imshow(image)
>>> top.set_title("Original image")
>>> middle.imshow(image_shifted_vertically)
>>> middle.set_title("Vertically shifted image")
>>> bottom.imshow(image_shifted_both_directions)
>>> bottom.set_title("Image shifted in both directions")
>>> fig.tight_layout()
r   r   r   r   r<   r   )r   rK   rC   r-   rP   NF)r   r   r   r#   r   r   r   scipy.ndimage._interpolationr   rE   r   r    r:   r
   rF   r"   r[   rX   rY   rZ   r   r^   )r$   r   r'   r%   r(   r7   r?   r   _shiftrH   r9   r8   rI   iis                 r)   r   r   z  s   R qyEAI788JJuEzzA~>??__U+N$$V>RF@E	Buzz5S2774=SFSuzz5S2774=SFSUQY0dC rzzM++D1D++E::>E !5RS5E!JJuBJJ/E;;!!

4Tu&M "s   *G$F)	grid_modec                \   US:  d  US:  a  [        S5      e[        R                  " U 5      n U R                  S:  a  [        S5      e[        R
                  " XR                  5      n[        [        U R                  U5       VV	s/ s H  u  p[        [        X-  5      5      PM     sn	n5      n
[        R                  " U 5      n[        R                  " X U
US9nU(       a|  SSKJn  [        X4US9nU" U R                   U4UR                   [        R                   " U5      S	.UD6  U" U R"                  U4UR"                  [        R"                  " U5      S	.UD6  U$ U(       a.  US:  a(  [%        XU5      u  p['        X[        R(                  US
9nOSnU nU(       a2  SnUS:X  a  SnOUS:X  a  SnUb  [*        R,                  " SU SU S3SS9  [        R.                  " U5      n[        R0                  " U
5      n[        R0                  " U R                  5      nU(       d
  US-  nUS-  n[        R2                  " UU[        R4                  " U R                  [        R(                  S9US:g  S9n[        R6                  " U5      n[8        R:                  " UUSX#XEUU5	        U$ s  sn	nf )a@  
Zoom an array.

The array is zoomed using spline interpolation of the requested order.

Parameters
----------
%(input)s
zoom : float or sequence
    The zoom factor along the axes. If a float, `zoom` is the same for each
    axis. If a sequence, `zoom` should contain one value for each axis.
%(output)s
order : int, optional
    The order of the spline interpolation, default is 3.
    The order has to be in the range 0-5.
%(mode_interp_constant)s
%(cval)s
%(prefilter)s
grid_mode : bool, optional
    If False, the distance from the pixel centers is zoomed. Otherwise, the
    distance including the full pixel extent is used. For example, a 1d
    signal of length 5 is considered to have length 4 when `grid_mode` is
    False, but length 5 when `grid_mode` is True. See the following
    visual illustration:

    .. code-block:: text

            | pixel 1 | pixel 2 | pixel 3 | pixel 4 | pixel 5 |
                 |<-------------------------------------->|
                                    vs.
            |<----------------------------------------------->|

    The starting point of the arrow in the diagram above corresponds to
    coordinate location 0 in each mode.

Returns
-------
zoom : ndarray
    The zoomed input.

Notes
-----
For complex-valued `input`, this function zooms the real and imaginary
components independently.

.. versionadded:: 1.6.0
    Complex-valued support added.

Examples
--------
>>> from scipy import ndimage, datasets
>>> import matplotlib.pyplot as plt

>>> fig = plt.figure()
>>> ax1 = fig.add_subplot(121)  # left side
>>> ax2 = fig.add_subplot(122)  # right side
>>> ascent = datasets.ascent()
>>> result = ndimage.zoom(ascent, 3.0)
>>> ax1.imshow(ascent, vmin=0, vmax=255)
>>> ax2.imshow(result, vmin=0, vmax=255)
>>> plt.show()

>>> print(ascent.shape)
(512, 512)

>>> print(result.shape)
(1536, 1536)
r   r   r   r   r<   r=   )r   rK   rC   r-   Nr3   r1   wrapz	grid-wrapz It is recommended to use mode = z instead of z when grid_mode is True.r,   rR   rP   )outwhere)r   r   r   r#   r   r[   tuplezipr>   introundr   r   rc   r   rE   r   r    r:   r
   rF   r\   r]   r"   r!   divide	ones_likeascontiguousarrayr   r^   )r$   r   r'   r%   r(   r7   r?   rf   re   jjr@   r   _zoomrH   r9   r8   rI   suggest_modezoom_divzoom_nominators                       r)   r   r     sL   N qyEAI788JJuEzzA~>??**4<D/25;;/EF/EVRSrw /EFHL__U+N$$V,4BDF>E	Bejj$Qv{{Q&Qejj$Qv{{Q&QUQY0dC rzzM:*LV^&L#MM3L>dV T+ ,
 ++D1Dxx%HXXekk*NA! 99^XekkD#q=*D %D4vd$"$M_ Gs   "J(
c	                 ^   [         R                  " U 5      n	U	R                  n
U
S:  a  [        S5      e[	        U5      n[        U5      S:w  a  [        S5      e[        U Vs/ s H  n[        U5      R                  5       PM     sn5      (       d  [        S5      eUS   S:  a  US==   U
-  ss'   US   S:  a  US==   U
-  ss'   US   S:  d  US   S:  d  US   U
:  d	  US   U
:  a  [        S5      eUR                  5         [        R                  " U5      [        R                  " U5      p[         R                  " X/U* U//5      n[         R                  " U	R                  5      nX   nU(       a@  Uu  nnUSSUU/SUSU//-  n[         R                  " USS9S	-   R!                  ["        5      nOX   nUUS-
  S-  -  nUS-
  S-  nUU-
  nUnUUU'   [%        U5      n[         R&                  " U	5      n[(        R*                  " XIUUS
9nU
S::  a  [-        XUUUXVXx5	        U$ [.        R0                  " [3        U
5       Vs/ s H!  nX;   a  [5        S5      /O[3        X   5      PM#     sn6 n[%        U5      nU H  nU	U   nUU   n[-        UUUUUXVXx5	        M      U$ s  snf s  snf )a(  
Rotate an array.

The array is rotated in the plane defined by the two axes given by the
`axes` parameter using spline interpolation of the requested order.

Parameters
----------
%(input)s
angle : float
    The rotation angle in degrees.
axes : tuple of 2 ints, optional
    The two axes that define the plane of rotation. Default is the first
    two axes.
reshape : bool, optional
    If `reshape` is true, the output shape is adapted so that the input
    array is contained completely in the output. Default is True.
%(output)s
order : int, optional
    The order of the spline interpolation, default is 3.
    The order has to be in the range 0-5.
%(mode_interp_constant)s
%(cval)s
%(prefilter)s

Returns
-------
rotate : ndarray
    The rotated input.

Notes
-----
For complex-valued `input`, this function rotates the real and imaginary
components independently.

.. versionadded:: 1.6.0
    Complex-valued support added.

Examples
--------
>>> from scipy import ndimage, datasets
>>> import matplotlib.pyplot as plt
>>> fig = plt.figure(figsize=(10, 3))
>>> ax1, ax2, ax3 = fig.subplots(1, 3)
>>> img = datasets.ascent()
>>> img_45 = ndimage.rotate(img, 45, reshape=False)
>>> full_img_45 = ndimage.rotate(img, 45, reshape=True)
>>> ax1.imshow(img, cmap='gray')
>>> ax1.set_axis_off()
>>> ax2.imshow(img_45, cmap='gray')
>>> ax2.set_axis_off()
>>> ax3.imshow(full_img_45, cmap='gray')
>>> ax3.set_axis_off()
>>> fig.set_layout_engine('tight')
>>> plt.show()
>>> print(img.shape)
(512, 512)
>>> print(img_45.shape)
(512, 512)
>>> print(full_img_45.shape)
(724, 724)

r,   z!input array should be at least 2Dz&axes should contain exactly two valuesz'axes should contain only integer valuesr   r   z invalid rotation plane specified)r&   g      ?r=   N)r   r   r#   rW   listrD   rV   float
is_integersortr   cosdgsindgr!   r>   ptpastyperm   rk   r   r   r   r   	itertoolsproductr.   slice)r$   angleaxesreshaper'   r%   r(   r7   r?   	input_arrr#   axcs
rot_matrix	img_shapein_plane_shapeiyix
out_boundsout_plane_shape
out_center	in_centerrO   r@   r   planes_coordrM   iaoas                                 r)   r   r   c  s   D 

5!I>>Dax<==:D
4yA~ABB62b	$$&677BCCAw{Q4Aw{Q4Aw{d1gkT!W_Q4;<<IIK==u!5qA6B7$ %J 

9??+I_NBAq"b>$%r1b>#3 3
 66*15;CCCH#/! 3q89J!#q(I#FL(L&L__Y/N$$Vl4BDF qyfd	7" M !((d%#"  "zuT{muY]/CC#%&  0'K;'B$BRV_d? ( Mw 7`%s   "#J%(J*)NNr   r3           T N)Nr   r3   r   T)r   NNr   r3   r   T))r   r   TNr   r3   r   T)r   r\   numpyr   scipy._lib._utilr   scipyr    r   r   _ni_docstringsr   __all__rF   r	   r
   r:   r   r   r   r   r   r   r   r*   r)   <module>r      s2  >    1    %M !"BJJ!U Un  ( H HV  59+,=A;?N Nb ;<9=e eP =A():>X Xv DGe eP BE|&+| |~ GH04G Gr*   