Reshaping 2 numpy dimensions into one with zipping?
I tried searching for this question but I couldn't find anything relevant.

The quickest way to describe the problem is with a simple example:
lets say I have a 2D numpy arrayl like this:

[[0, 1, 2, 3],
[10, 11, 12, 13],
[20, 21, 22, 23]]


So it has the shape [3,6]
I want to reshape it into a 1D array that looks like this:

[0, 10 ,20 ,1 ,11 ,21 ,2 ,12 ,22 ,3 ,13 ,23 ]


Unlike the array we get with reshape:

[ 0,  1,  2,  3, 10, 11, 12, 13, 20, 21, 22, 23]


Now, to the actual problem I have...
I actually have a 3D array and I want to reshape it into 2D array, and I want to do so with the method described above.
And another example would be:

import numpy
a = numpy.array([[[0,1,2],[10,11,12],[20,21,22]],
[[100,101,102],[110,111,112],[120,121,122]],
 [[200,201,202],[210,211,212],[220,221,222]]])
a.shape
a.reshape(3,9)
OUTPUT: array([[  0,   1,   2,  10,  11,  12,  20,  21,  22],
       [100, 101, 102, 110, 111, 112, 120, 121, 122],
       [200, 201, 202, 210, 211, 212, 220, 221, 222]])


And again, I want my output to look like this instead:

[[  0,  10,  20,   1,  11,  21,   2,  12,  22],
 [100, 110, 120, 101, 111, ..................],
 [...........................................]]


EDIT: just for the sake of people who google this problem, I add some search terms that some people might search for: 

Interweave dimensions numpy array

Zip dimensions numpy array

Numpy reshape ordered dimensions

Tensor reshape dimensions timesteps

We need to swap the last two axes with np.swapaxes or np.transpose and then reshape.

For 2D input case, it would be -

a.swapaxes(-2,-1).ravel()


For 3D input case, only the reshape part changes -

a.swapaxes(-2,-1).reshape(a.shape[0],-1)


Generic way : To make it generic that would cover all n-dim array cases -

a.swapaxes(-2,-1).reshape(a.shape[:-2] + (-1,)).squeeze()


Sample runs

2D case :

In [186]: a
Out[186]: 
array([[ 0,  1,  2,  3],
       [10, 11, 12, 13],
       [20, 21, 22, 23]])

In [187]: a.swapaxes(-2,-1).reshape(a.shape[:-2] + (-1,)).squeeze()
Out[187]: array([ 0, 10, 20,  1, 11, 21,  2, 12, 22,  3, 13, 23])


3D case :

In [189]: a
Out[189]: 
array([[[  0,   1,   2],
        [ 10,  11,  12],
        [ 20,  21,  22]],

       [[100, 101, 102],
        [110, 111, 112],
        [120, 121, 122]],

       [[200, 201, 202],
        [210, 211, 212],
        [220, 221, 222]]])

In [190]: a.swapaxes(-2,-1).reshape(a.shape[:-2] + (-1,)).squeeze()
Out[190]: 
array([[  0,  10,  20,   1,  11,  21,   2,  12,  22],
       [100, 110, 120, 101, 111, 121, 102, 112, 122],
       [200, 210, 220, 201, 211, 221, 202, 212, 222]])




Runtime test -

In [14]: a = np.random.rand(3,3,3)

# @mahdi n75's soln
In [15]: %timeit np.reshape(a,(3,9), order='F')
1000000 loops, best of 3: 1.22 µs per loop

In [16]: %timeit a.swapaxes(-2,-1).reshape(a.shape[0],-1)
1000000 loops, best of 3: 1.01 µs per loop

In [20]: a = np.random.rand(30,30,30)

# @mahdi n75's soln
In [21]: %timeit np.reshape(a,(30,900), order='F')
10000 loops, best of 3: 28.4 µs per loop

In [22]: %timeit a.swapaxes(-2,-1).reshape(a.shape[0],-1)
10000 loops, best of 3: 18.9 µs per loop

In [17]: a = np.random.rand(300,300,300)

# @mahdi n75's soln
In [18]: %timeit np.reshape(a,(300,90000), order='F')
1 loop, best of 3: 333 ms per loop

In [19]: %timeit a.swapaxes(-2,-1).reshape(a.shape[0],-1)
10 loops, best of 3: 52.4 ms per loop

