jax.scipy.ndimage.map_coordinates¶

jax.scipy.ndimage.map_coordinates(input, coordinates, order, mode='constant', cval=0.0)[source]¶

Map the input array to new coordinates by interpolation.

LAX-backend implementation of map_coordinates(). Only nearest neighbor (order=0), linear interpolation (order=1) and modes 'constant', 'nearest' and 'wrap' are currently supported. Note that interpolation near boundaries differs from the scipy function, because we fixed an outstanding bug (https://github.com/scipy/scipy/issues/2640); this function interprets the mode argument as documented by SciPy, but not as implemented by SciPy.

Original docstring below.

The array of coordinates is used to find, for each point in the output, the corresponding coordinates in the input. The value of the input at those coordinates is determined by spline interpolation of the requested order.

The shape of the output is derived from that of the coordinate array by dropping the first axis. The values of the array along the first axis are the coordinates in the input array at which the output value is found.

Parameters
  • input (array_like) – The input array.

  • coordinates (array_like) – The coordinates at which input is evaluated.

  • order (int, optional) – The order of the spline interpolation, default is 3. The order has to be in the range 0-5.

  • mode ({'reflect', 'constant', 'nearest', 'mirror', 'wrap'}, optional) – The mode parameter determines how the input array is extended beyond its boundaries. Default is ‘constant’. Behavior for each valid value is as follows:

  • cval (scalar, optional) – Value to fill past edges of input if mode is ‘constant’. Default is 0.0.

Returns

map_coordinates – The result of transforming the input. The shape of the output is derived from that of coordinates by dropping the first axis.

Return type

ndarray

See also

spline_filter(), geometric_transform(), scipy.interpolate()

Examples

>>> from scipy import ndimage
>>> a = np.arange(12.).reshape((4, 3))
>>> a
array([[  0.,   1.,   2.],
       [  3.,   4.,   5.],
       [  6.,   7.,   8.],
       [  9.,  10.,  11.]])
>>> ndimage.map_coordinates(a, [[0.5, 2], [0.5, 1]], order=1)
array([ 2.,  7.])

Above, the interpolated value of a[0.5, 0.5] gives output[0], while a[2, 1] is output[1].

>>> inds = np.array([[0.5, 2], [0.5, 4]])
>>> ndimage.map_coordinates(a, inds, order=1, cval=-33.3)
array([  2. , -33.3])
>>> ndimage.map_coordinates(a, inds, order=1, mode='nearest')
array([ 2.,  8.])
>>> ndimage.map_coordinates(a, inds, order=1, cval=0, output=bool)
array([ True, False], dtype=bool)