scipy.ndimage.minimum_position¶
- scipy.ndimage.minimum_position(input, labels=None, index=None)[源代码]¶
找出标签处数组的值的最小值的位置。
- 参数
- inputarray_like
值的类似数组。
- labelsARRAY_LIKE,可选
的最小值位置所在的不同区域进行标记的整数数组。 input 是要计算出来的。 labels 必须具有与的形状相同的形状 input 。如果 labels 则返回整个数组中第一个最小值的位置。
这个 labels 参数仅在以下情况下有效 index 是指定的。
- indexARRAY_LIKE,可选
查找最小值位置时考虑的区域标签列表。如果 index 为None,则
first
对所有元素的最小值,其中 labels 是非零的,则返回。这个 index 参数仅在以下情况下有效 labels 是指定的。
- 退货
- output整数的元组列表
整数的元组或指定的最小值位置的整数的元组列表 input 在由以下因素确定的区域范围内 labels 以及谁的索引在 index 。
如果 index 或 labels 的第一个最小值的位置,则返回一个整数元组。 input 。
示例
>>> 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)
可使用指定要处理的要素 labels 和 index :
>>> 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)]