np.unique()例子

Find the unique elements of an array.

Returns the sorted unique elements of an array. There are two optional outputs in addition to the unique elements: the indices of the input array that give the unique values, and the indices of the unique array that reconstruct the input array.

 

class = np.unique(mask)
n_class = len(mask)

class: array([0, 3, 4, 5], dtype=int16)

以上兩行就可以知道mask矩陣有哪些數,總共幾個不重複的數。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章