public int combineArrays(int[] a, int[] b) {   int[] result = new int[a.length + b.length];  int index = 0;  for (int i : a) {   result[index] = i;   index++; } for (int i : b) {    result[index] = i;   index++;  } return result;   } Apologies, here is the correct code.
14769
I need to concatenate two String arrays in Java.  void f(String[] first, String[] second) {     String[] both = ??? }   What is the easiest way to do this?
66573
I know that in JavaScript, creating a for loop like this: for(int i = 0; i &lt; arr.length; i++) is costly as it computes the array length each time. Is this behavior costly in c# for lists and arrays as well. Or at compile-time is it optimized?  Also what about other languages such as Java, how is this handled?
60272
Suppose I have 2 sets:  Set A: number of items $n= 10$, $\mu = 2.4$ , $\sigma = 0.8$  Set B: number of items $n= 5$, $\mu = 2$, $\sigma = 1.2$  I can find the combined mean ($\mu$) easily, but how am I supposed to find the combined standard deviation?
27323
I can't figure out how to use an array or matrix in the way that I would normally use a list. I want to create an empty array (or matrix) and then add one column (or row) to it at a time.  At the moment the only way I can find to do this is like:  mat = None for col in columns:     if mat is None:         mat = col     else:         mat = hstack((mat, col))   Whereas if it were a list, I'd do something like this:  list = [] for item in data:     list.append(item)   Is there a way to use that kind of notation for  arrays or matrices?
556
I have two Python dictionaries, and I want to write a single expression that returns these two dictionaries, merged (i.e. taking the union).  The update() method would be what I need, if it returned its result instead of modifying a dictionary in-place. &gt;&gt;&gt; x = {'a': 1, 'b': 2} &gt;&gt;&gt; y = {'b': 10, 'c': 11} &gt;&gt;&gt; z = x.update(y) &gt;&gt;&gt; print(z) None &gt;&gt;&gt; x {'a': 1, 'b': 10, 'c': 11}  How can I get that final merged dictionary in z, not x? (To be extra-clear, the last-one-wins conflict-handling of dict.update() is what I'm looking for as well.)
9898
Code like this often happens: l = [] while foo:     # baz     l.append(bar)     # qux  This is really slow if you're about to append thousands of elements to your list, as the list will have to be constantly resized to fit the new elements. In Java, you can create an ArrayList with an initial capacity. If you have some idea how big your list will be, this will be a lot more efficient. I understand that code like this can often be refactored into a list comprehension. If the for/while loop is very complicated, though, this is unfeasible. Is there an equivalent for us Python programmers?
17383
How do I concatenate two std::vectors?
111448
I have two iterators, a list and an itertools.count object (i.e. an infinite value generator). I would like to merge these two into a resulting iterator that will alternate yield values between the two:  &gt;&gt;&gt; import itertools &gt;&gt;&gt; c = itertools.count(1) &gt;&gt;&gt; items = ['foo', 'bar'] &gt;&gt;&gt; merged = imerge(items, c)  # the mythical "imerge" &gt;&gt;&gt; merged.next() 'foo' &gt;&gt;&gt; merged.next() 1 &gt;&gt;&gt; merged.next() 'bar' &gt;&gt;&gt; merged.next() 2 &gt;&gt;&gt; merged.next() Traceback (most recent call last):     ... StopIteration   What is the simplest, most concise way to do this?
69080
$${2\choose 2} {10\choose 3}+{3 \choose 2}{9 \choose 3}+{4 \choose 2}{8 \choose 3}+{5 \choose 2}{7 \choose 3}+{6 \choose 2}{6 \choose 3}+{7 \choose 2}{5 \choose 3}+{8 \choose 2}{4 \choose 3}+{9 \choose 2}{3 \choose 3}={13 \choose 6}$$   I am supposed to get the answer ${13\choose 6}$. I wonder if there is any formula for combination addition like this or are there some tricks to do this?
81191
I have two columns such as:  a   1  b   2  c    and I need to combine them like:  a   1 a   2 b   1 b   2 c   1 c   2   Is it possible with a formula?
5148
I have recently been thinking about the difference between the two ways of defining an array:   int[] array int array[]   Is there a difference?
6646
Background: I'm working on  for , and I've run into a problem with how I'm creating the individual matchups (groups of 4 entries).  Currently, I'm simply generating all combinations of 4 elements (in the combinatoric sense) of entries, but that gets really big really quickly:  $$x \choose 4$$    (from )  Therefore, my question is: How can I choose subsets (of length $n$) of a set such that each element of that set appears in the same subset as every other element at least once, while maintaining a minimal amount of subsets?  I can figure this out for $n = 2$, since the solution is quite intuitive: simply combine the first element with every other element, combine the second element with every other element that comes after it, etc. For a set of length $L$, this yields:  $$\sum_{x=1}^{L-1}(L - x)$$    (from )  which is much smaller and more manageable.  However, I still have not been able to figure out: How can I generalize this to any $n$?
49724
Take the following two lines of code:  for (int i = 0; i &lt; some_vector.size(); i++) {     //do stuff }   And this:  for (some_iterator = some_vector.begin(); some_iterator != some_vector.end();     some_iterator++) {     //do stuff }   I'm told that the second way is preferred. Why exactly is this?
88978
We write linear combination  of two spans as $a(1,1,1)+b(1,0,0)+c(1,1,0)$. Any vector $v$ in $\mathbb{R}^3$ can be expressed as $(a+b+c, a+b, a)$. Also linear combination of $W_2$ cannot form vector in $W_1$ other than $(0,0,0)$, $W_1\cap W_2=(0,0,0)$, and therefore direct sum is $\mathbb{R}^3$.  I am not sure if my method is correct, so could anyone help?
66844
How do you combine two jQuery search results? eg:  var $allFoos = $('.foo'),     $allBars = $('.bar')     $allFoosAndBars = $allFoos + $allBars;   Obviously, I just made up that last line, but I hope it makes it sorta clear what I mean. To be clear, the example is greatly simplified, and it could be any arbitrary sets i'm talking about, so $('.foo, .bar') is not what I'm after.
33605
\begin{array}{rrrrr|r}     b &amp; a &amp; a &amp; \cdot \cdot \cdot &amp; a \\     a &amp; b &amp; a &amp; \cdot \cdot \cdot &amp; a \\     a &amp; a &amp; b &amp; \cdot \cdot \cdot &amp; a \\     \cdot &amp; \cdot &amp; \cdot &amp; \space &amp; \cdot\\ \cdot &amp; \cdot &amp; \cdot &amp; \space &amp; \cdot\\ a &amp; a &amp; a &amp; \cdot \cdot  \cdot &amp; b   \end{array}  I have the above matrix $A\in M_{n\times n}(F)$ where $F$ is a field and $n\geq1$, $a,b\in F$.  I'm trying to find out how to use row operations to make it into an upper triangular matrix in order to figure out the determinant. But I'm not sure how I would approach it.
39841
How to use the  method?  Say I want to find number of combinations I can get with $x_1+x_2+x_3+x_4=22$,  where $x_i\in\mathbb{N}$.  Is this the correct time to apply the method?  This is being repurposed in an effort to cut down on duplicates, see here:     and here: