def interpolate_zeros(x, f):
    """
    For two float arrays of data, representing a 2d plot (x, f) in
    order - determine all the locations of x at which f crosses zero
    (using linear interpolation).  Return as a list.
    """
    assert len(x) == len(f)
    xcross = []
    for i in range(len(f) - 1):
        x0, x1 = x[i], x[i + 1]
        f0, f1 = f[i], f[i + 1]
        if (f0 >= 0. and f1 < 0.) or (f0 <= 0. and f1 > 0.):
            xcross.append(x0 - (x1 - x0) * f0 / (f1 - f0))
    return xcross