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

josef.pktd at gmail.com josef.pktd at gmail.com
Mon Nov 22 17:04:53 EST 2010


On Mon, Nov 22, 2010 at 4:53 PM, Dharhas Pothina
<Dharhas.Pothina at twdb.state.tx.us> wrote:
> 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.

just the last question

(np.diff(x) != 0)
np.nonzero(np.diff(x))

or some variation on it

Josef

>
> - dharhas
>
> _______________________________________________
> SciPy-User mailing list
> SciPy-User at scipy.org
> http://mail.scipy.org/mailman/listinfo/scipy-user
>



More information about the SciPy-User mailing list