I wrote a program that does the job, however it is not very pythonic, not pythonic and definitly not beautiful.
The program must concatenate two numpy arrays in the following manner:
As an example list0 and list1 are the input
list0 = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
list1 = [ 2, 3, 4, 5, 6, 7, 8, 9, 10, 11]
The output should look like the following:
[0, 2, 1, 3, 2, 4, 3, 5, 4, 6, 5, 7, 6, 8, 7, 9, 8, 10, 9, 11]
So basically put in the number of list0
at every even point of the output, and put in the number of list1
at every uneven point.
I am fairly new to python so I wrote it in a C-Style:
import numpy as np
list0 = np.arange(10)
list1 = np.arange(2,12)
new = []
cnt0 = 0
cnt1 = 0
for i in range(0,2*len(list0)):
if i % 2 == 0:
new.append(list0[cnt0])
cnt0 = cnt0 +1;
else:
new.append(list1[cnt1])
cnt1 = cnt1 +1;
Now I want to know if there is a more fancy, pythonic, faster way to achieve the same goal?