Function scipy.interpolate.griddata
allows to specify the keyword fill_value
, for which the doc states:
Value used to fill in for requested points outside of the convex hull of the input points. If not provided, then the default is nan. This option has no effect for the ‘nearest’ method.
However, I need to specify a fill_value
to use outside of the boundaries when
using method='nearest'
with 2D data. How can this be achieved?
This can be relatively easily achieved with the following work-around:
method='nearest'
method='linear'
; here the outside region is filled withnp.nan
.fill_value
to the result of 1.Code:
A less ad-hoc approach would be to compute the convex hull explicitly and use it to assign the fill value. This would require more effort but might run faster.