本文介紹了Python:從多維數組中刪除重復項的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!
問題描述
在 Python 中,numpy.unique
可以非常有效地從一維數組中刪除所有重復項.
In Python numpy.unique
can remove all duplicates from a 1D array, very efficiently.
1) 如何刪除二維數組中的重復行或列?
1) How about to remove duplicate rows or columns in a 2D array?
2) nD 數組怎么樣?
推薦答案
如果可能我會使用 pandas.
If possible I would use pandas.
In [1]: from pandas import *
In [2]: import numpy as np
In [3]: a = np.array([[1, 1], [2, 3], [1, 1], [5, 4], [2, 3]])
In [4]: DataFrame(a).drop_duplicates().values
Out[4]:
array([[1, 1],
[2, 3],
[5, 4]], dtype=int64)
這篇關于Python:從多維數組中刪除重復項的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!
【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!