If I have a list of points [x1, x2..xn, y1, y2..yn] how can I get [x1, y1, x2, y2..xn, yn] using numpy?
This is what I did, but idk how to continue
u = [x for idx, x in enumerate(l) if idx < len(l) / 2]
v = [x for idx, x in enumerate(l) if idx >= len(l) / 2]
>Solution :
Yo could use .reshape(2, -1), combined with .T for transpose and .flatten() to interpret the array as 1d again:
import numpy as np
# create example data: x1, ..., xn = [0, ..., 4] and y1, ..., yn = [5, ..., 9]
l = list(range(10))
# → [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
z = np.array(l).reshape(2, -1).T.flatten()
# → array([0, 5, 1, 6, 2, 7, 3, 8, 4, 9])