0

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?

0

1 Answer 1

1
# 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]
Sign up to request clarification or add additional context in comments.

1 Comment

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.