shuffle

Shuffling an Adapter [duplicate]

霸气de小男生 提交于 2020-08-06 07:01:58
问题 This question already has answers here : Random shuffling of an array (29 answers) Closed 7 years ago . I am using an Adapter : final ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, android.R.id.text1); and I want to shuffle the contents of it, however I discovered that Collections.shuffle(adapter); does not work. Is there another method to do this? While keeping the format of adapter i.e. not changing it to a List 回答1: Of course Collections

Shuffling part of a list in-place

孤人 提交于 2020-05-28 07:14:44
问题 I have a list and I want to shuffle a portion of it in-place . I am aware of random.shuffle() and that it works in-place, but if I slice the list, it shuffles the sliced copy of the original input, leaving the original list untouched: import random l = list(range(20)) print(l) # [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19] random.shuffle(l[:10]) # I wish it was shuffling the first half print(l) # but does nothing to `l` # [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13

Javascript: shuffling groups of objects in an array

本秂侑毒 提交于 2020-05-17 07:43:27
问题 I have an array of objects where I have sorted on a key ( group below) such that all of the objects wit hthe same value for group are adjacent to each other in the indices of data . For example: var data = [{foo: "cat", group:"house"}, {foo: "cat", group: "house"}, {foo: "cat", group: "tree"}, {foo: "dog", group: "tree"}, {foo: "dog", group: "car"}]; I am trying to shuffle the order of the objects in the data array while preserving the ordering within the values of the key group . In other

Efficient random generator for very large range (in python)

早过忘川 提交于 2020-05-10 07:50:49
问题 I am trying to create a generator that returns numbers in a given range that pass a particular test given by a function foo . However I would like the numbers to be tested in a random order. The following code will achieve this: from random import shuffle def MyGenerator(foo, num): order = list(range(num)) shuffle(order) for i in order: if foo(i): yield i The Problem The problem with this solution is that sometimes the range will be quite large ( num might be of the order 10**8 and upwards).

Efficient random generator for very large range (in python)

对着背影说爱祢 提交于 2020-05-10 07:49:08
问题 I am trying to create a generator that returns numbers in a given range that pass a particular test given by a function foo . However I would like the numbers to be tested in a random order. The following code will achieve this: from random import shuffle def MyGenerator(foo, num): order = list(range(num)) shuffle(order) for i in order: if foo(i): yield i The Problem The problem with this solution is that sometimes the range will be quite large ( num might be of the order 10**8 and upwards).

Shuffle a pandas dataframe by groups

大城市里の小女人 提交于 2020-05-08 03:00:06
问题 My dataframe looks like this sampleID col1 col2 1 1 63 1 2 23 1 3 73 2 1 20 2 2 94 2 3 99 3 1 73 3 2 56 3 3 34 I need to shuffle the dataframe keeping same samples together and the order of the col1 must be same as in above dataframe. So I need it like this sampleID col1 col2 2 1 20 2 2 94 2 3 99 3 1 73 3 2 56 3 3 34 1 1 63 1 2 23 1 3 73 How can I do this? If my example is not clear please let me know. 回答1: Assuming you want to shuffle by sampleID . First df.groupby , shuffle ( import random

Shuffle a pandas dataframe by groups

你说的曾经没有我的故事 提交于 2020-05-08 02:58:00
问题 My dataframe looks like this sampleID col1 col2 1 1 63 1 2 23 1 3 73 2 1 20 2 2 94 2 3 99 3 1 73 3 2 56 3 3 34 I need to shuffle the dataframe keeping same samples together and the order of the col1 must be same as in above dataframe. So I need it like this sampleID col1 col2 2 1 20 2 2 94 2 3 99 3 1 73 3 2 56 3 3 34 1 1 63 1 2 23 1 3 73 How can I do this? If my example is not clear please let me know. 回答1: Assuming you want to shuffle by sampleID . First df.groupby , shuffle ( import random

Data shuffling for Image Classification

╄→гoц情女王★ 提交于 2020-04-17 22:50:44
问题 I want to develop a CNN model to identify 24 hand signs in American Sign Language. I created a custom dataset that contains 3000 images for each hand sign i.e. 72000 images in the entire dataset. For training the model, I would be using 80-20 dataset split (2400 images/hand sign in the training set and 600 images/hand sign in the validation set). My question is: Should I randomly shuffle the images when creating the dataset? And Why? Based on my previous experience, it led to validation loss

Why is shuffling list(range(n)) slower than shuffling [0]*n?

元气小坏坏 提交于 2020-04-13 08:05:34
问题 Using random.shuffle , I noticed that shuffling list(range(n)) takes about 25% more time than shuffling [0] * n . Here are times for sizes n from 1 million to 2 million: Why is shuffling list(range(n)) slower? Unlike for sorting a list (which needs to look at the objects) or copying a list (which increases reference counters inside the objects), the objects shouldn't matter here. This should just rearrange pointers inside the list. I also tried numpy.random.shuffle , where shuffling list