if I have array: a=[1,2,3] b=[7,8,9] I want to get new array c=[1,7,2,8,3,9], which is alternating arrangement between a and b. How to use np.insert on that case?
1 Answer
# solution 1
import numpy as np
a=[1, 2, 3]
b=[7, 8, 9]
list(np.transpose((a,b)).flatten())
# output [1, 7, 2, 8, 3, 9]
# solution 2
import operator
a=[1, 2, 3]
b=[7, 8, 9]
reduce(operator.concat, map(lambda x, y : [x, y], a, b))
# output [1, 7, 2, 8, 3, 9]
1 Comment
Chris
Code dumps without any explanation are rarely helpful. Stack Overflow is about learning, not providing snippets to blindly copy and paste. Please edit your question and explain how it answers the specific question being asked. See How to Answer.