| Server IP : 35.80.110.71 / Your IP : 216.73.216.221 Web Server : Apache/2.4.58 (Ubuntu) System : Linux ip-172-31-21-44 6.17.0-1019-aws #19~24.04.1-Ubuntu SMP Tue Jun 23 18:53:06 UTC 2026 x86_64 User : ubuntu ( 1000) PHP Version : 8.3.31 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : OFF | Sudo : ON | Pkexec : OFF Directory : /lib/python3/dist-packages/scipy/interpolate/__pycache__/ |
Upload File : |
�
x�f�% � �t � d Z ddlZddlmZmZmZmZ ddlm Z g d�Z
G d� de� Zd ej d
fd�Z
y)zD
Convenience interface to N-D interpolation
.. versionadded:: 0.9
� N� )�LinearNDInterpolator�NDInterpolatorBase�CloughTocher2DInterpolator�_ndim_coords_from_arrays)�cKDTree)�griddata�NearestNDInterpolatorr r c � � e Zd ZdZdd�Zd� Zy)r
aL NearestNDInterpolator(x, y).
Nearest-neighbor interpolation in N > 1 dimensions.
.. versionadded:: 0.9
Methods
-------
__call__
Parameters
----------
x : (npoints, ndims) 2-D ndarray of floats
Data point coordinates.
y : (npoints, ) 1-D ndarray of float or complex
Data values.
rescale : boolean, optional
Rescale points to unit cube before performing interpolation.
This is useful if some of the input dimensions have
incommensurable units and differ by many orders of magnitude.
.. versionadded:: 0.14.0
tree_options : dict, optional
Options passed to the underlying ``cKDTree``.
.. versionadded:: 0.17.0
See Also
--------
griddata :
Interpolate unstructured D-D data.
LinearNDInterpolator :
Piecewise linear interpolant in N dimensions.
CloughTocher2DInterpolator :
Piecewise cubic, C1 smooth, curvature-minimizing interpolant in 2D.
interpn : Interpolation on a regular grid or rectilinear grid.
RegularGridInterpolator : Interpolation on a regular or rectilinear grid
in arbitrary dimensions (`interpn` wraps this
class).
Notes
-----
Uses ``scipy.spatial.cKDTree``
.. note:: For data on a regular grid use `interpn` instead.
Examples
--------
We can interpolate values on a 2D plane:
>>> from scipy.interpolate import NearestNDInterpolator
>>> import numpy as np
>>> import matplotlib.pyplot as plt
>>> rng = np.random.default_rng()
>>> x = rng.random(10) - 0.5
>>> y = rng.random(10) - 0.5
>>> z = np.hypot(x, y)
>>> X = np.linspace(min(x), max(x))
>>> Y = np.linspace(min(y), max(y))
>>> X, Y = np.meshgrid(X, Y) # 2D grid for interpolation
>>> interp = NearestNDInterpolator(list(zip(x, y)), z)
>>> Z = interp(X, Y)
>>> plt.pcolormesh(X, Y, Z, shading='auto')
>>> plt.plot(x, y, "ok", label="input point")
>>> plt.legend()
>>> plt.colorbar()
>>> plt.axis("equal")
>>> plt.show()
Nc � � t j | |||dd�� |�
t � }t | j fi |��| _ t
j |� | _ y )NF)�rescale�need_contiguous�need_values) r �__init__�dictr �points�tree�np�asarray�values)�self�x�yr
�tree_optionss �?/usr/lib/python3/dist-packages/scipy/interpolate/_ndgriddata.pyr zNearestNDInterpolator.__init__\ sQ � ��#�#�D�!�Q��49�05� 7� ���6�L��D�K�K�8�<�8�� ��j�j��m��� c �� � t || j j d �� }| j |� }| j |� }| j
j
|� \ }}| j | S )aV
Evaluate interpolator at given points.
Parameters
----------
x1, x2, ... xn : array-like of float
Points where to interpolate data at.
x1, x2, ... xn can be array-like of float with broadcastable shape.
or x1 can be array-like of float with shape ``(..., ndim)``
r )�ndim)r r �shape�_check_call_shape�_scale_xr �queryr )r �args�xi�dist�is r �__call__zNearestNDInterpolator.__call__e sa � � &�d����1B�1B�1�1E�
F��
�
#�
#�B�
'��
�]�]�2�
���)�)�/�/�"�%���a��{�{�1�~�r )FN)�__name__�
__module__�__qualname__�__doc__r r'