scipy.ndimage.maximum

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

计算已标记区域上数组的最大值。

参数
inputarray_like

值的类似数组。对于由指定的每个区域 labels ,最大值为 input 对该区域进行了计算。

labelsARRAY_LIKE,可选

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

indexARRAY_LIKE,可选

计算最大值时要考虑的区域标签列表。如果index为NONE,则为以下所有元素的最大值 labels 是非零的,则返回。

退货
output浮点数或浮点数列表

的最大值列表 input 在由以下因素确定的区域范围内 labels 以及谁的索引在 index 。如果 indexlabels 未指定,则返回一个浮点数: input 如果 labels 为NONE,且元素的最大值为 labels 如果出现以下情况,则大于零 index 是没有的。

注意事项

该函数返回Python列表而不是NumPy数组,请使用 np.array 若要将列表转换为数组,请执行以下操作。

示例

>>> a = np.arange(16).reshape((4,4))
>>> a
array([[ 0,  1,  2,  3],
       [ 4,  5,  6,  7],
       [ 8,  9, 10, 11],
       [12, 13, 14, 15]])
>>> labels = np.zeros_like(a)
>>> labels[:2,:2] = 1
>>> labels[2:, 1:3] = 2
>>> labels
array([[1, 1, 0, 0],
       [1, 1, 0, 0],
       [0, 2, 2, 0],
       [0, 2, 2, 0]])
>>> from scipy import ndimage
>>> ndimage.maximum(a)
15.0
>>> ndimage.maximum(a, labels=labels, index=[1,2])
[5.0, 14.0]
>>> ndimage.maximum(a, labels=labels)
14.0
>>> b = np.array([[1, 2, 0, 0],
...               [5, 3, 0, 4],
...               [0, 0, 0, 7],
...               [9, 3, 0, 0]])
>>> labels, labels_nb = ndimage.label(b)
>>> labels
array([[1, 1, 0, 0],
       [1, 1, 0, 2],
       [0, 0, 0, 2],
       [3, 3, 0, 0]])
>>> ndimage.maximum(b, labels=labels, index=np.arange(1, labels_nb + 1))
[5.0, 7.0, 9.0]