久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

從 numPy 數組列表中刪除重復項

Removing duplicates from a list of numPy arrays(從 numPy 數組列表中刪除重復項)
本文介紹了從 numPy 數組列表中刪除重復項的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

我有一個普通的 Python 列表,其中包含(多維)numPy 數組,所有數組都具有相同的形狀和相同數量的值.列表中的一些數組與之前的數組重復.

I have an ordinary Python list that contains (multidimensional) numPy arrays, all of the same shape and with the same number of values. Some of the arrays in the list are duplicates of earlier ones.

我的問題是我想刪除所有重復項,但是數據類型是 numPy 數組這一事實使這有點復雜......

I have the problem that I want to remove all the duplicates, but the fact that the data type is numPy arrays complicates this a bit...

? 我不能使用 set(),因為 numPy 數組不可散列.
? 我無法在插入過程中檢查重復項,因為數組是由函數批量生成并使用 .extend() 添加到列表中的.
? numPy 數組在不使用 numPy 自己的函數之一的情況下無法直接進行比較,所以我不能只使用if x in list"...
? 列表的內容需要在進程結束時保留為numPy 數組;我可以比較轉換為嵌套列表的數組的副本,但我不能將數組永久轉換為直接的 python 列表.

? I can't use set() as numPy arrays are not hashable.
? I can't check for duplicates during insertion, as the arrays are generated in batches by a function and added to the list with .extend().
? numPy arrays aren't directly comparable without resorting to one of numPy's own functions, so I can't just go something that uses "if x in list"...
? The contents of the list need to remain numPy arrays at the end of the process; I could compare copies of the arrays converted to nested lists, but I can't convert the arrays to straight python lists permanently.

關于如何在這里有效地刪除重復項有什么建議嗎?

Any suggestions on how I can remove duplicates efficiently here?

推薦答案

在這里使用解決方案:numpy 數組最有效的散列屬性 我們看到,如果 a 是一個 numpy 數組,散列最適合使用 a.tostring().所以:

Using the solutions here: Most efficient property to hash for numpy array we see that hashing works best with a.tostring() if a is an numpy array. So:

import numpy as np
arraylist = [np.array([1,2,3,4]), np.array([1,2,3,4]), np.array([1,3,2,4])]
L = {array.tostring(): array for array in arraylist}
L.values() # [array([1, 3, 2, 4]), array([1, 2, 3, 4])]

這篇關于從 numPy 數組列表中刪除重復項的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

相關文檔推薦

How to draw a rectangle around a region of interest in python(如何在python中的感興趣區域周圍繪制一個矩形)
How can I detect and track people using OpenCV?(如何使用 OpenCV 檢測和跟蹤人員?)
How to apply threshold within multiple rectangular bounding boxes in an image?(如何在圖像的多個矩形邊界框中應用閾值?)
How can I download a specific part of Coco Dataset?(如何下載 Coco Dataset 的特定部分?)
Detect image orientation angle based on text direction(根據文本方向檢測圖像方向角度)
Detect centre and angle of rectangles in an image using Opencv(使用 Opencv 檢測圖像中矩形的中心和角度)
主站蜘蛛池模板: 亚洲欧美成人 | 玩丰满女领导对白露脸hd | 精品国产欧美一区二区三区成人 | 精品一区精品二区 | 日韩在线视频网址 | 欧美高清视频在线观看 | 91色综合 | 国产一级视频 | 国产精品揄拍一区二区 | 欧美日韩精品专区 | 小视频你懂得 | 日韩成人专区 | 黄色大片免费网站 | 激情婷婷| 国产亚洲欧美日韩精品一区二区三区 | 日韩福利电影 | 黄色一级毛片 | 久久久久久av | 欧美日韩综合精品 | 手机在线观看av | 久久久久综合 | 成人一区二区电影 | av黄色在线 | 韩日精品一区 | 日韩精品一区二区三区中文字幕 | 欧洲一级黄 | 国产精品成人一区二区 | 激情欧美一区二区三区中文字幕 | 久久91精品| 狠狠操电影 | 日韩福利在线观看 | 中文字幕亚洲一区 | 奇米四色在线观看 | 久久久久国产一区二区三区四区 | 国产精品高潮呻吟久久 | 国产成都精品91一区二区三 | 亚洲成人免费视频在线观看 | 久久99精品国产自在现线小黄鸭 | 日本天堂一区 | 欧美一区二区三区视频 | 国产重口老太伦 |