数组python中的进程特定元素

数组python中的进程特定元素,python,Python,我有一个数组,是从互联网上得到的经过处理的数据中复制出来的,结果是 data=[[655.0,48.77,6.0,1']、0.0、[655.0,48.77,5.0,1']、1.0、[657.0,49.25,5.0,4']、2.2870067774276484、[657.0,49.25,1.0,1']、5.40651458890106、[657.0,49.25,1.0,5']、5.40651458890106] 我只是搞不清楚我是怎么读那个数组的。我想复制一个数据数组,使之成为一个新的数组,如 n

我有一个数组,是从互联网上得到的经过处理的数据中复制出来的,结果是
data=[[655.0,48.77,6.0,1']、0.0、[655.0,48.77,5.0,1']、1.0、[657.0,49.25,5.0,4']、2.2870067774276484、[657.0,49.25,1.0,1']、5.40651458890106、[657.0,49.25,1.0,5']、5.40651458890106]

我只是搞不清楚我是怎么读那个数组的。我想复制一个数据数组,使之成为一个新的数组,如

new=[[1',0.0],[1',1.0],[4',2.287006],[1',5.4065145],[5',5.4065145]。


最好的方面。

让我们假设您处理数据结构的恒定顺序,就像您在示例中提供的列表一样

如果我理解得很好:

您得到了一个嵌套列表和一些浮动的输入列表

[ [ A, B, C, D ], somefloat, [A, B, C, D ] somefloat ]
然后尝试获取一个嵌套列表列表,该列表使用第一个嵌套列表的最后一个元素,并将其与下一个浮点组合成一个新的嵌套列表,如下所示:

[ [D, somefloat], [D, somefloat] ]
data=[[655.0, 48.77, 6.0, '1'], 0.0, [655.0, 48.77, 5.0, '1'], 1.0, [657.0, 49.25, 5.0, '4'], 2.2870067774276484, [657.0, 49.25, 1.0, '1'], 5.40651458890106, [657.0, 49.25, 1.0, '5'], 5.40651458890106]

newdata = [[data[i][-1], data[i +1]] for i in range(0, len(data), 2)]
print(newdata)
一种解决方案是使用列表理解,如下所示:

[ [D, somefloat], [D, somefloat] ]
data=[[655.0, 48.77, 6.0, '1'], 0.0, [655.0, 48.77, 5.0, '1'], 1.0, [657.0, 49.25, 5.0, '4'], 2.2870067774276484, [657.0, 49.25, 1.0, '1'], 5.40651458890106, [657.0, 49.25, 1.0, '5'], 5.40651458890106]

newdata = [[data[i][-1], data[i +1]] for i in range(0, len(data), 2)]
print(newdata)
输出

[['1', 0.0], ['1', 1.0], ['4', 2.2870067774276484], ['1', 5.40651458890106], ['5', 5.40651458890106]]
让我们把它分解一下:

for i in range(0, len(data), 2) 
# will iterate through the first list, the range method here (starts from 0 to the length of the input list) will return the current index as "i" with step of two, for each iteration.

[data[i][-1]
#will take the current item (which is a nested list) and extract from it the last element, feel free to change the -1 by any index of the element you desire (if you decide to finally go with the third element, so change the -1 -which mean the last element- by 2 -which is the third element


data[i +1]
# will take the next element (which is the float number)

[data[i][-1], data[i +1]
# will put them in a nested list (feel free to use tuple or dict if you want to output another kind of nested data structure)

让我们假设您处理数据结构的恒定顺序,如您在示例中提供的列表

如果我理解得很好:

您得到了一个嵌套列表和一些浮动的输入列表

[ [ A, B, C, D ], somefloat, [A, B, C, D ] somefloat ]
然后尝试获取一个嵌套列表列表,该列表使用第一个嵌套列表的最后一个元素,并将其与下一个浮点组合成一个新的嵌套列表,如下所示:

[ [D, somefloat], [D, somefloat] ]
data=[[655.0, 48.77, 6.0, '1'], 0.0, [655.0, 48.77, 5.0, '1'], 1.0, [657.0, 49.25, 5.0, '4'], 2.2870067774276484, [657.0, 49.25, 1.0, '1'], 5.40651458890106, [657.0, 49.25, 1.0, '5'], 5.40651458890106]

newdata = [[data[i][-1], data[i +1]] for i in range(0, len(data), 2)]
print(newdata)
一种解决方案是使用列表理解,如下所示:

[ [D, somefloat], [D, somefloat] ]
data=[[655.0, 48.77, 6.0, '1'], 0.0, [655.0, 48.77, 5.0, '1'], 1.0, [657.0, 49.25, 5.0, '4'], 2.2870067774276484, [657.0, 49.25, 1.0, '1'], 5.40651458890106, [657.0, 49.25, 1.0, '5'], 5.40651458890106]

newdata = [[data[i][-1], data[i +1]] for i in range(0, len(data), 2)]
print(newdata)
输出

[['1', 0.0], ['1', 1.0], ['4', 2.2870067774276484], ['1', 5.40651458890106], ['5', 5.40651458890106]]
让我们把它分解一下:

for i in range(0, len(data), 2) 
# will iterate through the first list, the range method here (starts from 0 to the length of the input list) will return the current index as "i" with step of two, for each iteration.

[data[i][-1]
#will take the current item (which is a nested list) and extract from it the last element, feel free to change the -1 by any index of the element you desire (if you decide to finally go with the third element, so change the -1 -which mean the last element- by 2 -which is the third element


data[i +1]
# will take the next element (which is the float number)

[data[i][-1], data[i +1]
# will put them in a nested list (feel free to use tuple or dict if you want to output another kind of nested data structure)

因此,您希望从每个嵌套数组中提取最后一个字符串,并在..之后添加元素(不在嵌套数组中)?首先用文字说明要提取并放入
数据的哪些部分。出于您自己的目的,请随意使用您最熟悉的任何口头或书面语言。我想提取,正如我所说的,有一个我称之为标签的数字,包括(1,4,5),我想将该标签与我称之为距离的0.0、1.0、2.28700、5.406和5.406混合到新数组中。非常抱歉,英语不好。您是否希望从每个嵌套数组中得到最后一个字符串,以及..之后的元素(不在嵌套数组中)?首先用文字说明要提取并放入
数据的哪些部分。出于您自己的目的,请随意使用您最熟悉的任何口头或书面语言。我想提取,正如我所说的,有一个我称之为标签的数字,包括(1,4,5),我想将该标签与我称之为距离的0.0、1.0、2.28700、5.406和5.406混合到新数组中。谢谢,对不起,英语不好