| Server IP : 217.160.0.135 / Your IP : 216.73.217.85 Web Server : Apache System : Linux www 6.18.52-i1-ampere #1203 SMP Mon Sep 14 18:29:59 CEST 2026 aarch64 User : sws1074145052 ( 1074145052) PHP Version : 8.3.32 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : OFF | Sudo : OFF | Pkexec : OFF Directory : /lib/python3/dist-packages/scipy/interpolate/__pycache__/ |
Upload File : |
�
d�c# � �r � d Z ddlZddlmZmZmZmZ ddlm Z g d�Z
G d� de� � Zd ej d
fd�Z
dS )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� ZdS )r
a NearestNDInterpolator(x, y).
Nearest-neighbor interpolation in N > 1 dimensions.
.. versionadded:: 0.9
Methods
-------
__call__
Parameters
----------
x : (Npoints, Ndims) ndarray of floats
Data point coordinates.
y : (Npoints,) 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
Notes
-----
Uses ``scipy.spatial.cKDTree``
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()
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.
FNc � � t j | |||dd�� � |�t � � }t | j fi |��| _ t
j |� � | _ d S )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__W sg � ��#�D�!�Q��49�05� 7� 7� 7� 7� ���6�6�L��D�K�8�8�<�8�8�� ��j��m�m����� c �� � t || j j d �� � }| � |� � }| � |� � }| 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__` sg � � &�d���1B�1�1E�
F�
F�
F��
�
#�
#�B�
'�
'��
�]�]�2�
�
���)�/�/�"�%�%���a��{�1�~�r )FN)�__name__�
__module__�__qualname__�__doc__r r'