Wednesday, July 3, 2024
HomeLanguagesPythonPython SciPy – ndimage.map_coordinates() function

Python SciPy – ndimage.map_coordinates() function

This function is used to map the given array to new coordinates by interpolation. The array of coordinates is used to find, for each point in the output, the corresponding coordinates in the input. 

Syntax: scipy.ndimage.map_coordinates(input, coordinates, output=None, order=3,cval=0.0, prefilter=True)

Parameters

  • input:  which is of array_like – The input array.
  • coordinates: which is of array_like- The coordinates at which input is evaluated.
  • output:  which is an array – The array in which to place the output.
  • order:  which is of int, – it is optional,The order of the spline interpolation,
  • cval: it is a  scalar,-  it is optional,The  Value to fill past edges of input if mode is ‘constant’. Default is 0.0.
  • prefilter: it is of boolean type, it is optional. it is used to determine if the input array is prefiltered with spline_filter before interpolation.

Returns: map_coordinates: ndarray

Example 1:

Python3




# importing numpy package for
# creating arrays
import numpy as np
 
# importing scipy
from scipy import ndimage
 
# creating an array from 0 to 15 values
a = np.arange(16.).reshape((4, 4))
 
# finding coordinates
ndimage.map_coordinates(a, [[0.3, 1], [0.5, 1]], order=1)


 
 

Output:

 

array([1.7, 5. ])

 

Example 2:

 

Python3




# importing numpy package for
# creating arrays
import numpy as np
 
# importing scipy
from scipy import ndimage
 
a = np.arange(25.).reshape((5, 5))
 
vals = [[0.3, 1], [0.5, 1]]
 
# calculating mode
print(ndimage.map_coordinates(a, vals, order=1, mode='nearest'))
print(ndimage.map_coordinates(a, vals, order=1, cval=0, output=bool))
print(ndimage.map_coordinates(a, vals, order=1))


 
 

Output:

 

[2. 6.]
[ True True]
[2. 6.]

 

Calisto Chipfumbu
Calisto Chipfumbuhttp://cchipfumbu@gmail.com
I have 5 years' worth of experience in the IT industry, primarily focused on Linux and Database administration. In those years, apart from learning significant technical knowledge, I also became comfortable working in a professional team and adapting to my environment, as I switched through 3 roles in that time.
RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments