如何重新排列元组在Python列表中的行 [英] How to rearrange the rows in a list of tuples in Python

查看:320
本文介绍了如何重新排列元组在Python列表中的行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我参与以下难点:

我已经阅读<一href=\"http://stackoverflow.com/questions/22842289/python-generate-n-unique-random-numbers-within-a-range\">\"this\"和<一个href=\"http://stackoverflow.com/questions/13628725/how-to-generate-random-numbers-that-are-different\">\"this\",但没有解决方案。
我有它们标有57类12631的图像的列表。所以,这份名单有两个维度。第一维是图像,和第二维是其类的标签。标签的顺序分别来自56分别设置,55,54,53,...,0。我不想这样的订单。我希望所有的图像在这份名单中,但使用不同的或者随意的订单。结果
换句话说,我有一个名为randomData的元组下同图像列表:

每个个体元组是相同的,如下,以及:

有没有人帮我,我怎么可以重新安排这个名单?
谢谢你在前进。


解决方案

 导入随机
节点=拉链([[random.random()为i的范围(5)]为在范围Ĵ(57)],范围(57,-1,-1))
打印节点
random.shuffle(节点)
打印节点

I am involved in the following difficulty:

I already read the "this" and "this", but no solution. I have a list of 12631 images that they were labeled with 57 classes. So, this list has two dimensions. The first dimension is the images, and the second dimension is the labels of their classes. The order of labels were respectively arranged from 56, 55, 54, 53, ..., to 0, respectively. I do not want this orders. I want all images in this list, but with different or randomly orders.
In other words, I have a list of images called "randomData" with the tuples the same as below:

Each individual tuple is the same as below as well:

Is there anybody help me that how can I rearrange this list? Thank you in advance.

解决方案

import random
nodes = zip([[random.random() for i in range(5)] for j in range(57)],range(57,-1,-1))
print nodes
random.shuffle(nodes)
print nodes

这篇关于如何重新排列元组在Python列表中的行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆