【发布时间】:2017-09-19 12:04:48
【问题描述】:
我每三秒收到一些POST data(准确地说是 384 行)。这些存储在名为data 的列表中。然后我想将它们存储在列表helper 中,每个 POST 之后都会附加data。现在我想查看图中的数据,所以我需要将helper转换为numpy数组,称为myArr。
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
但是当我执行代码时,长度不一样:
>>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