repeat

How do I check if my array has repeated values inside it?

冷暖自知 提交于 2019-11-26 17:10:39
问题 So here is my array. double[] testArray = new double[10]; // will generate a random numbers from 1-20, too lazy to write the code I want to make a search loop to check if any values are being repeated. How do I do that? I would prefer not to use any special built-in methods since this is a small array. 回答1: You could do this with a little Linq: if (testArray.Length != testArray.Distinct().Count()) { Console.WriteLine("Contains duplicates"); } The Distinct extension method removes any

Repeat rows in a pandas DataFrame based on column value

大城市里の小女人 提交于 2019-11-26 16:59:37
问题 I have the following df: code . role . persons 123 . Janitor . 3 123 . Analyst . 2 321 . Vallet . 2 321 . Auditor . 5 The first line means that I have 3 persons with the role Janitors. My problem is that I would need to have one line for each person. My df should look like this: df: code . role . persons 123 . Janitor . 3 123 . Janitor . 3 123 . Janitor . 3 123 . Analyst . 2 123 . Analyst . 2 321 . Vallet . 2 321 . Vallet . 2 321 . Auditor . 5 321 . Auditor . 5 321 . Auditor . 5 321 . Auditor

repeat css background image a set number of times

守給你的承諾、 提交于 2019-11-26 16:23:37
问题 is there a way to set the number of times a background image repeats with css? 回答1: An ugly hack could be inserting multiple times —statically— the same image (using multiple backgrounds): E.g. To repeat horizontally an image (80x80) three times: background-image: url('bg_texture.png'), url('bg_texture.png'), url('bg_texture.png'); background-repeat: no-repeat, no-repeat, no-repeat; background-position: 0 top, 80px top, 160px top; Beware: not working on IE under 9 version (source). 回答2: no.

How to repeat Pandas data frame?

☆樱花仙子☆ 提交于 2019-11-26 16:04:29
问题 This is my data frame that should be repeated for 5 times: >>> x = pd.DataFrame({'a':1,'b':2},index = range(1)) >>> x a b 0 1 2 I wanna have the result like this: >>> x.append(x).append(x).append(x) a b 0 1 2 0 1 2 0 1 2 0 1 2 But there must be a way smarter than keep appending.. Actually the data frame Im working on should be repeated for 50 times.. I haven't found anything practical, including those like np.repeat ---- it just doesnt work on data frame. Could anyone help? 回答1: You can use

Repeat rows of a data.frame

梦想与她 提交于 2019-11-26 15:16:21
I want to repeat the rows of a data.frame, each N times. The result should be a new data.frame (with nrow(new.df) == nrow(old.df) * N ) keeping the data types of the columns. Example for N = 2: A B C A B C 1 j i 100 1 j i 100 --> 2 j i 100 2 K P 101 3 K P 101 4 K P 101 So, each row is repeated 2 times and characters remain characters, factors remain factors, numerics remain numerics, ... My first attempt used apply: apply(old.df, 2, function(co) rep(co, each = N)) , but this one transforms my values to characters and I get: A B C [1,] "j" "i" "100" [2,] "j" "i" "100" [3,] "K" "P" "101" [4,] "K

Combinations With Repetitions C#

我与影子孤独终老i 提交于 2019-11-26 14:25:18
问题 I need assistance with Combinations with Repetition. Have searched all over the net and although I found a few examples I can't understand them completely. My goal is simple a function (CombinationsWithRepetiion) receives list with items (in this case integer values) and length (that represents how long each combination can be) and returns a list containing the result. List<int> input = new List<int>() {1, 2, 3} CombinationsWithRepetition(input, length); result: length = 1: 1, 2, 3 length = 2

Create an array with same element repeated multiple times

自古美人都是妖i 提交于 2019-11-26 12:05:29
In Python, where [2] is a list, the following code gives this output: [2] * 5 # Outputs: [2,2,2,2,2] Does there exist an easy way to do this with an array in JavaScript? I wrote the following function to do it, but is there something shorter or better? var repeatelem = function(elem, n){ // returns an array with element elem repeated n times. var arr = []; for (var i = 0; i <= n; i++) { arr = arr.concat(elem); }; return arr; }; You can do it like this: function fillArray(value, len) { if (len == 0) return []; var a = [value]; while (a.length * 2 <= len) a = a.concat(a); if (a.length < len) a =

Do something every x minutes in Swift

我的梦境 提交于 2019-11-26 11:39:49
How can I run a function every minute? In JavaScript I can do something like setInterval , does something similar exist in Swift? Wanted output: Hello World once a minute... Unheilig var helloWorldTimer = NSTimer.scheduledTimerWithTimeInterval(60.0, target: self, selector: Selector("sayHello"), userInfo: nil, repeats: true) func sayHello() { NSLog("hello World") } Remember to import Foundation. Swift 4: var helloWorldTimer = Timer.scheduledTimer(timeInterval: 60.0, target: self, selector: #selector(ViewController.sayHello), userInfo: nil, repeats: true) @objc func sayHello() { NSLog("hello

Why did the ListView repeated every 6th item?

僤鯓⒐⒋嵵緔 提交于 2019-11-26 11:34:59
问题 I have a ListView that is filled by a Custom Adapter with a specific Layout. The Adapter is mapped to a HashMap with the specific Elements that contains the Data for each ListView Element. The Data in the hashMap is correct, but the ListView repeats to draw every 6\'th the same 6\'th Elements again, till it reaches the end of the Map?? My Display allows to display 5 items, if you sroll a litte it\'s 6 items. Here is the Code of the Adapter, the relevant Code of the ListActivity and the layout

Is there a regex flavor that allows me to count the number of repetitions matched by the * and + operators?

倖福魔咒の 提交于 2019-11-26 08:37:31
问题 Is there a regex flavor that allows me to count the number of repetitions matched by the * and + operators? I\'d specifically like to know if it\'s possible under the .NET Platform. 回答1: You're fortunate because in fact .NET regex does this (which I think is quite unique). Essentially in every Match , each Group stores every Captures that was made. So you can count how many times a repeatable pattern matched an input by: Making it a capturing group Counting how many captures were made by that