📜  Python SciPy – ndimage.map_coordinates()函数

📅  最后修改于: 2022-05-13 01:55:42.943000             🧑  作者: Mango

Python SciPy – ndimage.map_coordinates()函数

此函数用于通过插值将给定数组映射到新坐标。坐标数组用于为输出中的每个点查找输入中的相应坐标。

示例 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.arrange(16.).reshape((4, 4))
 
# finding coordinates
ndimage.map_coordinates(a, [[0.3, 1], [0.5, 1]], order=1)


Python3
# importing numpy package for
# creating arrays
import numpy as np
 
# importing scipy
from scipy import ndimage
 
a = np.arrange(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))


输出:

array([1.7, 5. ])

示例 2:

蟒蛇3

# importing numpy package for
# creating arrays
import numpy as np
 
# importing scipy
from scipy import ndimage
 
a = np.arrange(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))

输出:

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