Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/360.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/arrays/12.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_Arrays_List_Numpy_Dictionary - Fatal编程技术网

Python:如何向命名多维数组添加列表

Python:如何向命名多维数组添加列表,python,arrays,list,numpy,dictionary,Python,Arrays,List,Numpy,Dictionary,在PHP中,您可以轻松创建和填充多维数组,如下所示: $points = array(); $points["Landmarks"]["Latitude"] = $some_array_containing_lat_values; $points["Landmarks"]["Longitude"] = $some_array_containing_lon_values; 什么是蟒蛇式的方法 我已经尝试过列表、字典和numpy数组,但都不起作用。使用未命名(编号)数组不是一个选项,因为它们是从结

在PHP中,您可以轻松创建和填充多维数组,如下所示:

$points = array();
$points["Landmarks"]["Latitude"] = $some_array_containing_lat_values;
$points["Landmarks"]["Longitude"] = $some_array_containing_lon_values;
什么是蟒蛇式的方法

我已经尝试过列表、字典和numpy数组,但都不起作用。使用未命名(编号)数组不是一个选项,因为它们是从结构和命名不一致的外部文件创建的,因此必须按名称而不是索引从数组中检索数据


如果这是一个重复的问题,很抱歉,但是我已经搜索了一整天都没有用了,而且我的时间非常紧迫。

无论何时,当您想使用字符串作为关键字(例如“Landmarks”)从数据结构中检索项时,您都需要一本字典

要拥有
点[“地标”][“纬度”]
的“多维”功能,您必须在另一个字典中有一个字典:

points = {'Landmarks': {'Latitude': lat_array, 'Longitude': lon_array}}
您还可以使用支持嵌套字典的
deafultdict

from collections import deafaultdict
points = defaultdict(dict)
points["Landmarks"]["Latitude"] = lat_array
points["Landmarks"]["Longitude"] = lon_array

您可以查看有关嵌套字典的更多信息。

无论何时,只要您想使用字符串作为关键字(例如“Landmarks”)从数据结构中检索项,您都需要字典

要拥有
点[“地标”][“纬度”]
的“多维”功能,您必须在另一个字典中有一个字典:

points = {'Landmarks': {'Latitude': lat_array, 'Longitude': lon_array}}
您还可以使用支持嵌套字典的
deafultdict

from collections import deafaultdict
points = defaultdict(dict)
points["Landmarks"]["Latitude"] = lat_array
points["Landmarks"]["Longitude"] = lon_array

您可以查看有关嵌套字典的更多信息。

我不明白为什么字典不起作用?只需要分别启动不同的级别:
points={}
points['Landmarks']={}
points['Landmarks']['Latitude']]=lat_数组
,等等。如果要跳过
points['Landmarks':{'lat lat u数组}
,则,您可以使用defaultdict--
points=defaultdict(dict)
points['Landmarks']['Latitude']=lat_array
——而不是快速浏览PHP文档,这表明
array
在某种意义上结合了Python
字典
列表
的功能。在Python中,这些属性本质上不是多维的,但它们都可以包含字典或列表作为值,从而产生一种多维性。您可能需要展示一些Python测试,并解释每个测试的问题所在。到目前为止,问题描述太笼统了。我不明白为什么字典不起作用?只需要分别启动不同的级别:
points={}
points['Landmarks']={}
points['Landmarks']['Latitude']]=lat_数组
,等等。如果要跳过
points['Landmarks':{'lat lat u数组}
,则,您可以使用defaultdict--
points=defaultdict(dict)
points['Landmarks']['Latitude']=lat_array
——而不是快速浏览PHP文档,这表明
array
在某种意义上结合了Python
字典
列表
的功能。在Python中,这些属性本质上不是多维的,但它们都可以包含字典或列表作为值,从而产生一种多维性。您可能需要展示一些Python测试,并解释每个测试的问题所在。到目前为止,问题描述太笼统了。非常感谢,defaultdict做到了!单独启动这些级别也很有效。非常感谢,defaultdict完成了这个任务!单独启动这些级别也会起作用。