scipy.ndimage.

minimum_position#

scipy.ndimage.minimum_position(input, labels=None, index=None)[源]#

查找数组在指定标签区域内的最小值位置。

参数:
input类数组

值的类数组。

labels类数组,可选

一个整数数组,用于标记计算 input 最小值位置的不同区域。labels 必须与 input 具有相同的形状。如果未指定 labels,则返回整个数组中第一个最小值的位置。

labels 参数仅在指定 index 时有效。

index类数组,可选

一个区域标签列表,用于确定最小值的计算位置。如果 index 为 None,则返回 labels 不为零的所有元素中的第一个最小值。

index 参数仅在指定 labels 时有效。

返回:
output整数元组列表

一个整数元组或整数元组列表,用于指定 input 在由 labels 确定且其索引在 index 中的区域内的最小值位置。

如果未指定 indexlabels,则返回一个整数元组,指定 input 中第一个最小值的位置。

示例

>>> import numpy as np
>>> a = np.array([[10, 20, 30],
...               [40, 80, 100],
...               [1, 100, 200]])
>>> b = np.array([[1, 2, 0, 1],
...               [5, 3, 0, 4],
...               [0, 0, 0, 7],
...               [9, 3, 0, 0]])
>>> from scipy import ndimage
>>> ndimage.minimum_position(a)
(2, 0)
>>> ndimage.minimum_position(b)
(0, 2)

可以使用 labelsindex 指定要处理的特征。

>>> label, pos = ndimage.label(a)
>>> ndimage.minimum_position(a, label, index=np.arange(1, pos+1))
[(2, 0)]
>>> label, pos = ndimage.label(b)
>>> ndimage.minimum_position(b, label, index=np.arange(1, pos+1))
[(0, 0), (0, 3), (3, 1)]