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

在 python 列表中獲取唯一的元組,無論順序如何

Grab unique tuples in python list, irrespective of order(在 python 列表中獲取唯一的元組,無論順序如何)
本文介紹了在 python 列表中獲取唯一的元組,無論順序如何的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

我有一個 python 列表:

[(2,2),(2,3),(1,4),(2,2) 等...]

我需要的是某種功能,將其簡化為獨特的組件...在上面的列表中:

[ (2,2),(2,3),(1,4) ]

<小時>

numpy unique 并沒有完全做到這一點.我可以想到一種方法——將我的元組轉換為數字,[22,23,14,etc.],找到唯一的,然后從那里開始工作......但我沒有不知道復雜性是否會失控.有沒有一個函數可以做我想要對元組做的事情?

<小時>

下面是演示問題的代碼示例:

 將 numpy 導入為 npx = [(2,2),(2,2),(2,3)]y = np.unique(x)

<塊引用>

返回:y: [2 3]

這里是演示修復的解決方案的實現:

 x = [(2,2),(2,2),(2,3)]y = 列表(集合(x))

<塊引用>

返回 y: [(2,2),(2,3)]

解決方案

你可以這樣做

y = np.unique(x, axis=0)z = []對于 y 中的 i:z.append(元組(i))

原因是 numpy 將元組列表解釋為二維數組.通過設置axis = 0,您會要求numpy不要展平數組并返回唯一的行.

I have a python list:

[ (2,2),(2,3),(1,4),(2,2), etc...]

What I need is some kind of function that reduces it to its unique components... which would be, in the above list:

[ (2,2),(2,3),(1,4) ]


numpy unique does not quite do this. I can think of a way to do it--convert my tuples to numbers, [22,23,14,etc.], find the uniques, and work back from there...but I don't know if the complexity won't get out of hand. Is there a function that will do what I am trying to do with tuples?


Here is a sample of code that demonstrates the problem:

 import numpy as np

 x = [(2,2),(2,2),(2,3)]
 y = np.unique(x)

returns: y: [2 3]

And here is the implementation of the solution that demonstrates the fix:

 x = [(2,2),(2,2),(2,3)]
 y = list(set(x))

returns y: [(2,2),(2,3)]

解決方案

you could simply do

y = np.unique(x, axis=0)
z = [] 
for i in y:
   z.append(tuple(i))

The reason is that a list of tuples is interpreted by numpy as a 2D array. By setting axis=0, you'd be asking numpy not to flatten the array and return unique rows.

這篇關于在 python 列表中獲取唯一的元組,無論順序如何的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持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| 欧美激情一区二区三级高清视频 | 91精品国产91 | 国产精品美女久久久久久不卡 | 日韩中文字幕视频在线观看 | 精品中文在线 | 久久伊人精品一区二区三区 | 91久久精品 | 日韩精品在线免费观看视频 | 亚洲精品久久久9婷婷中文字幕 | 在线观看成年人视频 | 国产精品永久在线观看 | 男人的天堂中文字幕 | 久久精品一区 | 国产免费一级片 | 91看片免费 | 波多野结衣一区二区三区 | 手机在线观看av | 欧美日韩高清免费 | 午夜精品视频 | 亚洲成人免费观看 | 国产一区 在线视频 | 三极网站| 不卡在线视频 | 国产欧美一级二级三级在线视频 | 91精品国产综合久久久动漫日韩 | 欧美日韩亚洲国产 | 国产日韩一区二区三免费高清 | 午夜视频网站 | 九九热免费视频在线观看 | 日韩在线观看 | 91精品国模一区二区三区 | 国产黄色电影 | 欧美成人精品一区二区男人看 | 国产第1页| 中文字幕一区二区三区四区五区 | 欧美视频在线看 | 午夜影院在线 |