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

從 numPy 數(shù)組列表中刪除重復(fù)項(xiàng)

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

問題描述

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

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.

我的問題是我想刪除所有重復(fù)項(xiàng),但是數(shù)據(jù)類型是 numPy 數(shù)組這一事實(shí)使這有點(diǎn)復(fù)雜......

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(),因?yàn)?numPy 數(shù)組不可散列.
? 我無法在插入過程中檢查重復(fù)項(xiàng),因?yàn)閿?shù)組是由函數(shù)批量生成并使用 .extend() 添加到列表中的.
? numPy 數(shù)組在不使用 numPy 自己的函數(shù)之一的情況下無法直接進(jìn)行比較,所以我不能只使用if x in list"...
? 列表的內(nèi)容需要在進(jìn)程結(jié)束時(shí)保留為numPy 數(shù)組;我可以比較轉(zhuǎn)換為嵌套列表的數(shù)組的副本,但我不能將數(shù)組永久轉(zhuǎn)換為直接的 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.

關(guān)于如何在這里有效地刪除重復(fù)項(xiàng)有什么建議嗎?

Any suggestions on how I can remove duplicates efficiently here?

推薦答案

在這里使用解決方案:numpy 數(shù)組最有效的散列屬性 我們看到,如果 a 是一個(gè) numpy 數(shù)組,散列最適合使用 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])]

這篇關(guān)于從 numPy 數(shù)組列表中刪除重復(fù)項(xiàng)的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

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

相關(guān)文檔推薦

How to draw a rectangle around a region of interest in python(如何在python中的感興趣區(qū)域周圍繪制一個(gè)矩形)
How can I detect and track people using OpenCV?(如何使用 OpenCV 檢測(cè)和跟蹤人員?)
How to apply threshold within multiple rectangular bounding boxes in an image?(如何在圖像的多個(gè)矩形邊界框中應(yīng)用閾值?)
How can I download a specific part of Coco Dataset?(如何下載 Coco Dataset 的特定部分?)
Detect image orientation angle based on text direction(根據(jù)文本方向檢測(cè)圖像方向角度)
Detect centre and angle of rectangles in an image using Opencv(使用 Opencv 檢測(cè)圖像中矩形的中心和角度)
主站蜘蛛池模板: 成人免费在线视频 | 97国产精品| 在线国产一区二区 | 久久久一区二区三区四区 | 国产99在线 | 欧美 | 国产成人免费一区二区60岁 | 奇米av | 91在线视频播放 | 成人一级视频在线观看 | 欧美精品久久久 | 在线播放中文字幕 | 日韩免费三级 | 日韩精品一区二区三区高清免费 | 久久久久一区二区三区四区 | 亚洲精品成人av | 久久久久中文字幕 | 一区二区国产精品 | 最新91在线| 国产日韩欧美二区 | 日韩中文在线 | 国产精品1区2区3区 国产在线观看一区 | 国产1页 | 国产在线精品一区二区三区 | 亚洲视频一区在线观看 | 国产日韩一区二区 | 国产精品亚洲精品 | 亚洲综合五月天婷婷 | 黄色在线| 欧美精品乱码99久久影院 | 91久久久久久 | 久久99精品久久久久久国产越南 | 亚洲成人免费 | 情侣av| 国产精品永久免费视频 | 国产美女精品 | 久久一二区 | 久久久久久亚洲精品 | 国产真实精品久久二三区 | 中文字幕在线精品 | 色综合天天网 | 亚洲精品乱码久久久久久按摩观 |