'How do i make a list with x1,y1,x2,y2,x3,y3.... into (x1,y1), (x2,y2), (x3,y3)
the two input list are coordinates x and y. They are input separately, and I am trying to combine the two input into xy coordinates in array form.
I am trying to make two list into an array
for example here is the two individual list: x = [x1,x2,x3,x4] y = [y1,y2,y3,y4]
then I combine the input into one list:
xy=[x for y in(x, y) for x in y]
where it is arrange in [x1,y1,x2,y2,x3,y3,x4,y4]
however I'm stuck in the next step which is making it into an array that has this order
array_xy = ((x1,y1),(x2,y2),(x3,y3),(x4,y4))
Any idea how can I make the xy list into the array_xy?
Solution 1:[1]
You can make it directly from x and y with zip:
list(zip(x, y))
I hope I understand what you want correctly.
By the way, I think xy is [x1, x2, x3, x4, y1, y2, y3, y4] how you wrote it.
But you can construct what you want from it like this:
array_xy = [(xy[i], xy[i+len(x)]) for i in range(len(x))]
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 |
