# [SciPy-User] Interpolate between duplicate points for non monotonic array.

Dharhas Pothina Dharhas.Pothina@twdb.state.tx...
Mon Nov 22 15:53:14 CST 2010

```Hi,

A while back I asked a question about interpolating between duplicate point for a monotonic array. 	I was able to get that working with the code below.

x = np.array([1.0,1.0,1.0,2.0,2.0,3.0,3.0,3.0,4.0,4.0,5.0,5.0,5.0,5.0,6.0,6.0])
xUnique, xUniqueIndices = np.unique(x, return_index=True)
idx = np.argsort(xUniqueIndices)
np.interp(np.arange(len(x)), xUniqueIndices[idx], xUnique[idx])

gives :

np.array([ 1.        ,  1.33333333,  1.66666667,  2.        ,  2.5       ,
3.        ,  3.33333333,  3.66666667,  4.        ,  4.5       ,
5.        ,  5.25      ,  5.5       ,  5.75      ,  6.        ,  6.        ])

now I need to do something similar for a non-monotonic array: i.e

x = np.array([ 1.,  1.,  1.,  2.,  2.,  3.,  3.,  3.,  4.,  4.,  2.,  2.,  1., 1.,  1.,  6.])

newx = np.array([1., 1.33, 1.67, 2., 2.5, 3., 3.33, 3.67, 4., 3., 2., 3., 4., 5., 6.])

I've tried a few things but nothing has worked yet. as a corrolary question: is there a way to identify the indices on the array x that are the start of adjacent duplicate elements i.e a version np.unique that only uniques adjacent values.

- dharhas

```