I am trying to fulfill an array with the data from other two variables
my code is like:
import numpy as np
x1 = [200,50,125,275,350]
x2 = [475,575,700,700,575]
#array = np.array([[200,475],[50,575],[125,700],[275,700],[350,575]])
array = np.array(
for j in range(5):
#for i in range(2):
[x1[i],x2[i]]
)
thank you in advance
Expected Result array([[200,475],
[50,575],
[125,700],
[275,700],
[350,575]])
>Solution :
You can use zip then convert to list and use numpy.asarray to get as array Or you can use numpy.column_stack.
import numpy as np
x1 = [200,50,125,275,350]
x2 = [475,575,700,700,575]
res = np.asarray(list(zip(x1,x2)))
res_2 = np.column_stack((x1,x2))
>>> res
array([[200, 475],
[ 50, 575],
[125, 700],
[275, 700],
[350, 575]])
>>> res_2
array([[200, 475],
[ 50, 575],
[125, 700],
[275, 700],
[350, 575]])