I have an array that looks something like this:

```
A = [.36, .4, .43, .48, .53, .58, .63, .68, .72, .77, .82, .86, .93, .95, .97, .99, 1, 0.99, .97, .95, .92, .88, .85, .80, .76, .71, .66, .61, .56, .51, .47, .43, .40]

```

I want to be able to take the value to the left and right of 1, and find their average, and then extend +1 in each direction of 1. So that my new array is

```
 A =[1, (.99 +.99)/2, (.97 + .97)/2, (.95 + .95)/2, ......, (.36 + .40)/2]

```

Initially I was trying to do this:

```
import numpy as np
import itertools

A = [.36, .4, .43, .48, .53, .58, .63, .68, .72, .77, .82, .86, .93, .95, .97, .99, 1, 0.99, .97, .95, .92, .88, .85, .80, .76, .71, .66, .61, .56, .51, .47, .43, .40]
A = np.sort(A)
A = list(itertoools.chain.from_iterable[i]*n for i in [sum(A[i:i+n])/n for i in range(0, len(A)),n)]))
A = A[1::2]
A = A[::-1]

```

So what this does is re-order my list from least to greatest (sort), and then take the average of each value next to it (the `iter`tools and `A[1::2]` command), then re-order backwards (the `A[::-1]` line). But i've found this does that incorrectly, more particularly in the average section due to the resort. It re-sorts it properly, but then that causes the average to be taken improperly as `.4` moves next to `.36`, and then I have two `0.43s` right next to each other after that, which leads my tail values to have incorrect averages.

I'd be happy to supply any more information for any particular questions.

Thanks!