Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python: how to combine two flat lists into a 2D array? [duplicate]

Tags:

python

arrays

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

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]

EDIT

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.

like image 248
FaCoffee Avatar asked Jan 04 '17 15:01

FaCoffee


People also ask

How do I merge two lists into a list in Python?

Concatenate Two Lists in Python In almost all simple situations, using list1 + list2 is the way you want to concatenate lists. The edge cases below are better in some situations, but + is generally the best choice. All options covered work in Python 2.3, Python 2.7, and all versions of Python 31.

How do you create a double list in Python?

Suppose that two numbers are given: the number of rows of n and the number of columns m . You must create a list of size n × m , filled with, say, zeros. This can be easily seen if you set the value of a[0][0] to 5 , and then print the value of a[1][0] — it will also be equal to 5.


1 Answers

list(zip(lat, long))

gives

[(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)]

More on zip here

like image 112
Patrick Haugh Avatar answered Sep 30 '22 02:09

Patrick Haugh