Merge two vectors with alternate locations
<p>I have:</p>

<pre><code>import numpy as np
A = np.asarray([1,3,5,7,9])
B = np.asarray([2,4,6,8,10])
</code></pre>

<p>I want to create:</p>

<pre><code>C = np.asarray([1,2,3, 4,5,6,7,8,9,10])
</code></pre>

<p>Is there a better way to do than to run a for loop</p>

<p>You can the <em>stack</em> arrays vertically using <a href="http://docs.scipy.org/doc/numpy/reference/generated/numpy.vstack.html#numpy.vstack" rel="nofollow"><code>vstack</code></a>, <em>transpose</em> and then <a href="http://docs.scipy.org/doc/numpy-1.10.1/reference/generated/numpy.ravel.html" rel="nofollow"><code>ravel</code></a>:</p>

<pre><code>&gt;&gt;&gt; A = np.asarray([1,3,5,7,9])
&gt;&gt;&gt; B = np.asarray([2,4,6,8,10])
&gt;&gt;&gt; C = np.vstack((A, B)).T.ravel()
&gt;&gt;&gt; C
array([ 1,  2,  3,  4,  5,  6,  7,  8,  9, 10])
</code></pre>

python numpy