Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/list/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在Python中追加列表的问题_Python_List_Numpy_Append - Fatal编程技术网

在Python中追加列表的问题

在Python中追加列表的问题,python,list,numpy,append,Python,List,Numpy,Append,我每三秒收到一些POST数据(准确地说是384行)。这些数据存储在名为数据的列表中。然后我想将它们存储在listhelper中,在每篇文章之后都会添加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

我每三秒收到一些
POST数据
(准确地说是384行)。这些数据存储在名为
数据的列表中。然后我想将它们存储在list
helper
中,在每篇文章之后都会添加
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 = [1,2,3]
>>> helper = []
>>> helper.append(data)
>>> helper
[[1, 2, 3]]
>>> len(helper)
1

我无法从你的问题中理解为什么你需要
helper
列表,而是需要(浅层)复制问题
helper=data[:]
helper.extend(data)
。因为我不确定你要从这里走到哪里,我将留下这个答案,告诉你为什么你的
helper
列表现在只有一个元素。

如果你想连接列表,你可以简单地做
list\u c=list\u a+list\u b
或者在你的情况下
helper+=data
谢谢你的回答,我明白了,我正在0中创建某种金字塔。名单索引:D
>>> data = [1,2,3]
>>> helper = []
>>> helper.append(data)
>>> helper
[[1, 2, 3]]
>>> len(helper)
1