久久久久久久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 檢測圖像中矩形的中心和角度)
主站蜘蛛池模板: 亚洲精品成人网 | 欧美亚洲在线 | 亚洲一区免费视频 | 亚洲毛片在线 | 久久精品二区 | 在线观看av免费 | 欧美在线观看视频 | 久久亚洲国产 | 国产精品99久久久久久www | 久久精品久久精品 | 五月婷婷综合在线 | 欧美专区在线观看 | 国产亚洲一区二区三区 | 亚洲天天| 亚洲一区网站 | av在线小说| 激情五月激情综合网 | 久久18| 欧美日韩免费视频 | 欧美日韩一区二区在线 | 亚洲一区精品视频 | 欧美日韩国产三级 | 96久久 | 国产一区二区福利 | 黄色精品视频 | 九九久久精品 | 精东影业一区二区三区 | 欧美午夜在线观看 | 久久少妇| 亚洲激情欧美 | 97福利视频 | 婷婷久久久 | 色婷婷中文字幕 | 久精品视频 | 特一级黄色片 | 成人av免费看 | 午夜在线观看视频网站 | 狠狠干美女 | 日韩一区二区在线视频 | 国产中文在线 | 精品日韩av|