scipy.ndimage.
minimum_position#
- scipy.ndimage.minimum_position(input, labels=None, index=None)[原始碼]#
尋找陣列在標籤位置上的最小值位置。
- 參數:
- inputarray_like
數值的類陣列。
- labelsarray_like, optional
一個整數陣列,標記不同的區域,在這些區域上計算 input 的最小值位置。labels 必須與 input 具有相同的形狀。如果未指定 labels,則傳回整個陣列中第一個最小值的位置。
labels 參數僅在指定 index 時才有效。
- indexarray_like, optional
一個區域標籤列表,用於考量尋找最小值的位置。如果 index 為 None,則傳回
first
在 labels 為非零的所有元素上的最小值。index 參數僅在指定 labels 時才有效。
- 返回:
- outputlist of tuples of ints
整數元組或整數元組列表,指定 input 在由 labels 確定的區域上的最小值位置,且其索引在 index 中。
如果未指定 index 或 labels,則傳回一個整數元組,指定 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)
可以使用 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)]