Reformat table in Python
<p>I have a table in a Python script with numpy in the following shape:</p>

<pre><code>[array([[a1, b1, c1], ..., [x1, y1, z1]]), 
 array([a2, b2, c2, ..., x2, y2, z2])
]
</code></pre>

<p>I would like to reshape it to a format like this:</p>

<pre><code>(array([[a2],
        [b2],
         .
         .
         .
        [z2]],
        dtype = ...),
 array([[a1],
        [b1],
         .
         .
         .
        [z1]])
)
</code></pre>

<p>To be honest, I'm also quite confused about the different parentheses. array1, array2] is a list of arrays, right? What is (array1, array2), then?</p>

<p>Round brackets <code>(1, 2)</code> are <a href="https://docs.python.org/3/library/stdtypes.html#tuple" rel="nofollow">tuples</a>, square brackets <code>[1, 2]</code> are <a href="https://docs.python.org/3/library/stdtypes.html#list" rel="nofollow">lists</a>. To convert your data structure, use <a href="http://docs.scipy.org/doc/numpy/reference/generated/numpy.expand_dims.html" rel="nofollow"><code>expand_dims</code></a> and <a href="http://docs.scipy.org/doc/numpy/reference/generated/numpy.ndarray.flatten.html" rel="nofollow"><code>flatten</code></a>.</p>



<pre><code>import numpy as np

a = [
    np.array([[1, 2, 3], [4, 5, 6]]),
    np.array([10, 11, 12, 13, 14])
    ]
print(a)

b = (
    np.expand_dims(a[1], axis=1),
    np.expand_dims(a[0].flatten(), axis=1)
    )

print(b)
</code></pre>

python numpy