我每三秒钟收到一些POST data
(正好是384行)。这些存储在名为data
的列表中。然后我想将它们存储在列表helper
中,每次POST后都会附加data
。现在我想检查图中的数据,所以我需要将helper
转换为numpy数组,这就是所谓的myArr
。在Python中追加列表的问题
data = json.loads(json_data)["data"] #I get some data
helper=[] #Then create list
helper.append(data) # And here I would like to add values to the end
myArr=np.asarray(helper)
self.send_response(200)
self.send_header("Content-type", "text/html")
self.end_headers()
self.wfile.write("")
print (len(data))
print(type (data))
print (len(helper))
print(type (helper))
print (len(myArr))
print(type (myArr))
print data
但是,当我执行的代码中,lenghts是不一样的:
>>384
>><type 'list'>
>>1
>><type 'list'>
>>1
>><type 'numpy.ndarray'>
这个名单data
内容是这样的:
[[0.46124267578125, 0.0545654296875, 0.89111328125, 0.0, 0.0, 0.0, 0.0],
[0.46124267578125, 0.0545654296898, 0.89111328125, 0.0, 0.0, 0.0, 0.0],
[0.46124267578125, 0.0545654296875, 0.89111328125, 0.0, 0.0, 0.0, 0.0],
[0.4637451171875, 0.05804443359362, 0.8892822265625, 0.0, 0.0, 0.0, 0.0],
[0.4637451171875, 0.05804443359301, 0.8892822265625, 0.0, 0.0, 0.0, 0.0],
[0.4637451171875, 0.05804443359375, 0.8892822265625, 0.0, 0.0, 0.0, 0.0],
[etc.]]
我觉得只是有问题我无法弄清楚的列表维度。
如果你想连接列表,你可以简单地做''list_c = list_a + list_b''或者你的情况''helper + = data'' –