def derivative(xdata, ydata):
    """
    performs d(ydata)/d(xdata) with nearest-neighbor slopes
    must be well-ordered, returns new arrays [xdata, dydx_data]

    neighbors:
    """
    D_ydata = []
    D_xdata = []
    for n in range(1, len(xdata) - 1):
        D_xdata.append(xdata[n])
        D_ydata.append((ydata[n + 1] - ydata[n - 1]) / (xdata[n + 1] -
            xdata[n - 1]))
    return [D_xdata, D_ydata]
