Advanced array concatenation python
<p>Say I have four multi-dimensional arrays - </p>

<pre><code>a = [["a","a","a"],
    ["a","a","a"],
    ["a","a","a"]]
b = [["b","b","b"],
    ["b","b","b"],
    ["b","b","b"]]
c = [["c","c","c"],
    ["c","c","c"],
    ["c","c","c"]]
d = [["d","d","d"],
    ["d","d","d"],
    ["d","d","d"]]
</code></pre>

<p>and I want to combine them into a single array like</p>

<pre><code>total = [["a","a","a","b","b","b"],
        ["a","a","a","b","b","b"],
        ["a","a","a","b","b","b"], 
        ["c","c","c","d","d","d"],
        ["c","c","c","d","d","d"],
        ["c","c","c","d","d","d"]]
</code></pre>

<p>How would I do it?</p>

<p><em>I am doing it for  spelunky-style map generation</em></p>

<p>Since you are talking about arrays, using numpy arrays and <code>hstack()</code> and <code>vstack()</code>:</p>

<pre><code>import numpy as np

ab = np.hstack((np.array(a),np.array(b)))
cd = np.hstack((np.array(c),np.array(d)))

print np.vstack((ab,cd))
</code></pre>

<p>Which leads you:</p>

<pre><code>[['a' 'a' 'a' 'b' 'b' 'b']
 ['a' 'a' 'a' 'b' 'b' 'b']
 ['a' 'a' 'a' 'b' 'b' 'b']
 ['c' 'c' 'c' 'd' 'd' 'd']
 ['c' 'c' 'c' 'd' 'd' 'd']
 ['c' 'c' 'c' 'd' 'd' 'd']]
</code></pre>

<p>Alternatively, using <code>concatenate()</code>:</p>

<pre><code>ab = np.concatenate((np.array(a),np.array(b)),axis=1)
cd = np.concatenate((np.array(c),np.array(d)),axis=1)

print np.concatenate((ab,cd))
</code></pre>

python arrays pygame concatenation