scipy.ndimage.maximum_position

scipy.ndimage.maximum_position(input, labels=None, index=None)[源代码]

找出标签处数组的值的最大值的位置。

对于由指定的每个区域 labels 的最大值的位置。 input 在区域内返回。

参数
inputarray_like

值的类似数组。

labelsARRAY_LIKE,可选

的最大值所在的不同区域进行标记的整数数组。 input 是要计算出来的。 labels 必须具有与的形状相同的形状 input 。如果 labels 则返回整个数组中第一个最大值的位置。

这个 labels 参数仅在以下情况下有效 index 是指定的。

indexARRAY_LIKE,可选

查找最大值位置时要考虑的区域标签列表。如果 index 为NONE,为所有元素的第一个最大值,其中 labels 是非零的,则返回。

这个 index 参数仅在以下情况下有效 labels 是指定的。

退货
output整数的元组列表

指定最大值位置的整数元组列表 input 在由以下因素确定的区域范围内 labels 以及谁的索引在 index

如果 indexlabels ,则返回一个整数元组,指定 first 的最大值 input

示例

>>> from scipy import ndimage
>>> a = np.array([[1, 2, 0, 0],
...               [5, 3, 0, 4],
...               [0, 0, 0, 7],
...               [9, 3, 0, 0]])
>>> ndimage.maximum_position(a)
(3, 0)

可使用指定要处理的要素 labelsindex

>>> lbl = np.array([[0, 1, 2, 3],
...                 [0, 1, 2, 3],
...                 [0, 1, 2, 3],
...                 [0, 1, 2, 3]])
>>> ndimage.maximum_position(a, lbl, 1)
(1, 1)

如果未给出索引,则返回非零值 labels 已处理:

>>> ndimage.maximum_position(a, lbl)
(2, 3)

如果没有最大值,则返回第一个元素的位置:

>>> ndimage.maximum_position(a, lbl, 2)
(0, 2)