scipy.ndimage.

maximum_position#

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

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

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

参数:
inputarray_like

类似数组的值。

labelsarray_like, optional

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

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

indexarray_like, optional

一个区域标签列表,用于查找最大值的位置。如果 index 为 None,则返回 labels 非零的所有元素中的第一个最大值。

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

返回:
output由整数元组组成的列表

由整数元组组成的列表,指定由 labels 确定且其索引位于 index 中的区域内 input 最大值的位置。

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

示例

>>> from scipy import ndimage
>>> import numpy as np
>>> 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)

如果没有给定 index,则处理非零的 labels

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

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

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