interpolate.py 文件源码

python
阅读 25 收藏 0 点赞 0 评论 0

项目:BAG_framework 作者: ucb-art 项目源码 文件源码
def __call__(self, xi):
        """Interpolate at the given coordinate.

        Parameters
        ----------
        xi : numpy.array
            The coordinates to evaluate, with shape (..., ndim)

        Returns
        -------
        val : numpy.array
            The interpolated values at the given coordinates.
        """
        ext = self._ext
        ndim = self.ndim
        xi = self._normalize_inputs(xi)
        ans_shape = xi.shape[:-1]
        xi = xi.reshape(-1, ndim)

        ext_idx_vec = False
        for idx in range(self.ndim):
            ext_idx_vec = ext_idx_vec | (xi[:, idx] < ext) | (xi[:, idx] > self._max[idx])

        int_idx_vec = ~ext_idx_vec
        xi_ext = xi[ext_idx_vec, :]
        xi_int = xi[int_idx_vec, :]
        ans = np.empty(xi.shape[0])
        ans[int_idx_vec] = imag_interp.map_coordinates(self._filt_values, xi_int.T, mode='nearest', prefilter=False)
        if xi_ext.size > 0:
            if not self._extrapolate:
                raise ValueError('some inputs are out of bounds.')
            ans[ext_idx_vec] = self._extfun(xi_ext)

        if ans.size == 1:
            return ans[0]
        return ans.reshape(ans_shape)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号