Python:如何将两个平面列表组合成2D数组? [英] Python: how to combine two flat lists into a 2D array?

查看:131
本文介绍了Python:如何将两个平面列表组合成2D数组?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个平面的地理坐标列表(纬度,经度),需要将它们组合成2D数组或矩阵.

I have two flat lists of geographical coordinates (lat, long), and I need to combine them into a 2D array or matrix.

它们现在存储在数据框中:

They are now stored in a dataframe:

    lat         lon
0   48.010258   -6.156909
1   48.021648   -6.105887
2   48.033028   -6.054801
3   48.044384   -6.003691
4   48.055706   -5.952602
5   48.067017   -5.901447
6   48.078304   -5.850270
7   48.089558   -5.799114
8   48.100800   -5.747891

如何将这两个列表组合成2D数组,以便保留 lat-lon 对应关系?这些是纯数据:

How can I combine these two lists into a 2D array so that the lat-lon correspondence is preserved? These are the plain data:

lat=[48.01,48.02,48.03,48.04,48.05,48.06,48.07,48.08,48.10]
lon=[-6.15,-6.10,-6.05,-6.00,-5.95,-5.90,-5.85,-5.79,-5.74]

编辑

这些摘录的数据表示(经纬度)(y,x)地理地图.合并后,它们将重现下图.您清楚地看到预期结果的存在将必须剥夺一定宽度的外部数据框架.因此,就像切出图片的外部框架一样,该框架的宽度为30个数据点.

These excerpted data represent a (lat, long) or (y, x) geographical map. Combined, they reproduce the below image. You clearly see the presence of The intended outcome will have to be deprived of an outer frame of data of a certain width. So it's like cutting out an outer frame of a picture, the width of which is 30 data points.

推荐答案

list(zip(lat, long))

给予

[(48.01, -6.15), (48.02, -6.1), (48.03, -6.05), (48.04, -6.0), 
 (48.05, -5.95), (48.06, -5.9), (48.07, -5.85), (48.08, -5.79), (48.1, -5.74)]

zip的更多信息此处

这篇关于Python:如何将两个平面列表组合成2D数组?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆