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矩阵有哪些数,总共几个不重复的数。
更多数学原理小文请关注公众号:未名方略