I am currently working on my Final Major Project and I could use some help on an issue I am having.
Basically I have an Array that contains 12 other arrays that have 68 Elements inside.
What I would like to do is to get all elements of that array to split each element of all 12 arrays and put them into a different array.
E.G: All of these arrays are inside a main array
Main Array = [
Array1 =
[[ 54, 93],
[ 55, 114],
[ 58, 135]]
Array2 =
[[ 44, 99],
[ 46, 122],
[ 48, 143]]
Array3 =
[[ 47, 89],
[ 49, 112],
[ 54, 134]]
]
My Target should look like this:
X_Array = [[54, 44. 47],
[55, 46, 49],
[58, 48, 54]]
Y_Array = [[93, 99, 89],
[114, 122, 112],
[135, 143, 134]]
I can also provide actual Data from output if that helps.
答案 0 :(得分:1)
所以你在这里看到的是2个嵌套for循环,其中,对于每个内部数组,你构建两个较小的数组,每个数组只有x坐标或y坐标。重新开始。您可以跟踪要添加的较小数组中的哪个位置。在构建较小的数组之后,只需将它们添加到更大的x数组和y数组列表中。
x_arr = []
y_arr = []
sub_length = len(Main_Array[0])
for i in range(sub_length):
tmp_x = []
tmp_y = []
for array in Main_Array:
tmp_x.append(array[i][0])
tmp_y.append(array[i][1])
x_arr.append(tmp_x)
y_arr.append(tmp_y)
print x_arr, y_arr