Question: I have one array and i want to convert it into certain shape which I do not know how to do.

I tried, but it does not give me proper result.

Here is the array-:
this is a numpy array

```
a=[[ [1,2,13],
     [12,2,32],
     [61,2,6],
     [1,23,3],
     [1,21,3],
     [91,2,38] ]]

```

expected outputs-:

```
1. [[ [1,2],
      [12,2],
      [61,2],
      [1,23],
      [1,21], 
      [91,2] ]]

2.  [ [1,2],
       [12,2],
       [61,2],
       [1,23],
       [1,21],
       [91,2] ]

```

Answer: 
You could use `.apply(...)`

```
def get_length(group):

  coords = group[['lat', 'lon']].values
  p1, p2 = coords[0], coords[-1]

  length = vincenty(p1, p2).m

  return length

```

---

```
grouped = df.groupby(by=['id'])
length = grouped.apply(get_length).rename('length')

df.merge(length, on=['id'])

```

---

```
    id     lat         lon       length
0   1   41.144540   -8.562926   2712.533677
1   1   41.144540   -8.562926   2712.533677
2   1   41.163172   -8.583821   2712.533677
3   2   41.163233   -8.583838   5.597993
4   2   41.163198   -8.583886   5.597993

```
You can get the first and last values in a single command using `groupby()` and [`agg()`](https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.core.groupby.DataFrameGroupBy.aggregate.html) (aka `aggregate()`):

```
df.groupby('id').agg({'lat': ['first', 'last'], 'lon': ['first', 'last']})

```

That gives you:

```
          lat                  lon          
        first       last     first      last
id                                          
1   41.144540  41.163172 -8.562926 -8.583821
2   41.163233  41.163198 -8.583838 -8.583886

```

Which is almost exactly what you need to feed to `vincenty()` to compute the distances for each `id`.