nimble.fill.interpolate

nimble.fill.interpolate(vector, match, **kwarguments)

Fill matched values with the interpolated value.

The fill value is determined by the piecewise linear interpolant returned by numpy.interp. By default, the unmatched values will be used as the discrete data points, but additional arguments for numpy.interp can be passed as keyword arguments.

Parameters:
  • vector (nimble point or feature) – A nimble Base object containing one point or feature.

  • match (value or function) –

    • value - The value which should be filled if it occurs in the data.

    • function - Input a value and return True if that value should be filled. Nimble offers common use-case functions in its match module.

  • kwarguments – Collection of extra key:value argument pairs to pass to numpy.interp.

Returns:

list – The vector values with the interpolated values replacing the match values.

Examples

Match a value.

>>> lst = [1, 'na', 3, 'na', 5]
>>> X = nimble.data(lst)
>>> interpolate(X, 'na')
<DataFrame 1pt x 5ft
     0    1    2    3    4
   ┌──────────────────────
 0 │ 1  2.000  3  4.000  5
>

Match using a function from nimble’s match module.

>>> from nimble import match
>>> lst = [6, 0, 4, 0, 2]
>>> X = nimble.data(lst)
>>> interpolate(X, match.zero)
<Matrix 1pt x 5ft
       0      1      2      3      4
   ┌──────────────────────────────────
 0 │ 6.000  5.000  4.000  3.000  2.000
>