python-去除二维数组中的重复行

之前提到去除一维数组中的重复元素用unique()函数,如果要去除二维数组中的重复行该怎么操作呢?

import numpy as np
arr = np.array([[1, 2],[3, 4],[5, 6],[7, 8],[3, 4],[1, 2]])
print(np.array(list(set([tuple(t) for t in arr]))))
输出:[[1 2]
       [3 4]
       [5 6]
       [7 8]]

猜你喜欢

转载自blog.csdn.net/u012991043/article/details/81067207