shuffle

How to shuffle array in PostgreSQL 9.6 and also lower versions?

对着背影说爱祢 提交于 2019-12-14 03:55:27
问题 The following custom stored function - CREATE OR REPLACE FUNCTION words_shuffle(in_array varchar[]) RETURNS varchar[] AS $func$ SELECT array_agg(letters.x) FROM (SELECT UNNEST(in_array) x ORDER BY RANDOM()) letters; $func$ LANGUAGE sql STABLE; was shuffling character array in PostgreSQL 9.5.3: words=> select words_shuffle(ARRAY['a','b','c','d','e','f']); words_shuffle --------------- {c,d,b,a,e,f} (1 row) But now after I have switched to PostgreSQL 9.6.2 the function stopped working: words=>

spark调优(二):资源调优

穿精又带淫゛_ 提交于 2019-12-14 00:47:27
转发学习自美团技术团队: https://tech.meituan.com 建议继续阅读之前先对这篇文章的内容有一定了解: Apache Spark 内存管理详解 推荐阅读: spark调优(一):开发调优 资源调优概述 在开发完Spark作业之后,就该为作业配置合适的资源了。Spark的资源参数,基本都可以在spark-submit命令中作为参数设置。很多Spark初学者,通常不知道该设置哪些必要的参数,以及如何设置这些参数,最后就只能胡乱设置,甚至压根儿不设置。资源参数设置的不合理,可能会导致没有充分利用集群资源,作业运行会极其缓慢;或者设置的资源过大,队列没有足够的资源来提供,进而导致各种异常。总之,无论是哪种情况,都会导致Spark作业的运行效率低下,甚至根本无法运行。因此我们必须对Spark作业的资源使用原理有一个清晰的认识,并知道在Spark作业运行过程中,有哪些资源参数是可以设置的,以及如何设置合适的参数值。 1、Spark作业基本运行原理 详细原理见上图。我们使用spark-submit提交一个Spark作业之后,这个作业就会启动一个对应的Driver进程。根据你使用的部署模式(deploy-mode)不同,Driver进程可能在本地启动,也可能在集群中某个工作节点上启动。Driver进程本身会根据我们设置的参数,占有一定数量的内存和CPU core

how to shuffle numbers with textarea in javascript

跟風遠走 提交于 2019-12-13 22:46:17
问题 If I put numbers into a textarea like so: 418484 418485 418486 I want them to get shuffled, and I want an output like this: 418485 418484 418486 I don't want the values changed - I just want some JavaScript or jQuery that will shuffle these numbers and give me the result in my web page. 回答1: I found this great shuffle function from this answer: function shuffle(array) { var currentIndex = array.length, temporaryValue, randomIndex; // While there remain elements to shuffle... while (0 !==

How to shuffle a text file on disk in Python

旧街凉风 提交于 2019-12-13 17:28:36
问题 I am working with a text file of about 12*10^6 rows which is stored on my hard disk. The structure of the file is: data|data|data|...|data\n data|data|data|...|data\n data|data|data|...|data\n ... data|data|data|...|data\n There's no header, and there's no id to uniquely identify the rows. Since I want to use it for machine learning purposes, I need to make sure that there's no order in the text file which may affect the stochastic learning. Usually I upload such kind of files into memory,

Randomizing/Shuffling rows in a dataframe in pandas

谁说胖子不能爱 提交于 2019-12-13 14:17:04
问题 I am currently trying to find a way to randomize items in a dataframe row-wise. I found this thread on shuffling/permutation column-wise in pandas (shuffling/permutating a DataFrame in pandas), but for my purposes, is there a way to do something like import pandas as pd data = {'day': ['Mon', 'Tues', 'Wed', 'Thurs', 'Fri'], 'color': ['Blue', 'Red', 'Green', 'Yellow', 'Black'], 'Number': [11, 8, 10, 15, 11]} dataframe = pd.DataFrame(data) Number color day 0 11 Blue Mon 1 8 Red Tues 2 10 Green

What is the best algorithm to shuffle cards? [closed]

落花浮王杯 提交于 2019-12-13 12:52:32
问题 Closed. This question is off-topic. It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed 3 years ago . Given a finite set of N cards, what is the best way (algorithm) to shuffle the cards so I will have the best shuffled pack of cards with minimum steps to get maximum random permutations? What is the best solution in minimum steps? 回答1: Use Fisher Yates algorithm. Many programming languages use variant of this

Better way to shuffle two related lists

南楼画角 提交于 2019-12-13 11:33:08
问题 Is there better ways to randomly shuffle two related lists without breaking their correspondence in the other list? I've found related questions in numpy.array and c# but not exactly the same one. As a first try, a simple zip trick will do: import random a = [[1, 2], [3, 4], [5, 6], [7, 8], [9, 10]] b = [2, 4, 6, 8, 10] c = zip(a, b) random.shuffle(c) a = [e[0] for e in c] b = [e[1] for e in c] print a print b It will get the output: [[1, 2], [7, 8], [3, 4], [5, 6], [9, 10]] [2, 8, 4, 6, 10]

Error: __init__() got an unexpected keyword argument 'n_splits'

馋奶兔 提交于 2019-12-13 11:01:46
问题 I am going to perform ShuffleSplit() method for California housing dataset (Source: https://www.dcc.fc.up.pt/~ltorgo/Regression/cal_housing.html) to fit SGD regression. However, the 'n_splits' error is occurred when method is applied. The code is following: from sklearn import cross_validation, grid_search, linear_model, metrics import numpy as np import pandas as pd from sklearn.preprocessing import scale from sklearn.cross_validation import ShuffleSplit housing_data = pd.read_csv('cal

php random array - random again when doing while [duplicate]

ⅰ亾dé卋堺 提交于 2019-12-13 09:45:05
问题 This question already has answers here : php random order from a foreach (3 answers) Closed 6 years ago . Right now, every single time I do a while do, it goes from top to bottom of my array. How can I make it go through each value but in a random mode, not from top to bottom? Here's what I have: $xbb = array('avotf1', 'avotf2', 'avotf3', 'avotf4', 'avotf5', 'avotf6', 'avotf7', 'avotf8', 'avotf9', 'avotf11', 'avotf12', 'avotf13', 'avotf14', 'avotf15', 'avotf10'); foreach($xbb as $item) { echo

Making a quiz with shuffled questions

蹲街弑〆低调 提交于 2019-12-13 08:29:11
问题 I am wanting to join the Royal Air Force and thought as a good way to prepare I should code myself a quiz about their aircraft. There are 28 aircraft that I have added to the quiz. For example - 'Where is the Typhoon FGR4 based?' And then I have 7 seconds to think before the options pop up for me to answer. Instead of the quiz just going from the first to last question in the same order each time I would like it to be shuffled. Here is the quiz in pastebin http://pastebin.com/wxVus42W Also