Exemple #1
0
def vector_apply(f, x, *arg):
    """
    apply **f** to array **x** with given arguments fast. This is a fast
    version of::

        np.array([f(xi,*arg) for xi in x ])

    useful when you try to plot something
    """
    return _vector_apply(f, x, arg)
Exemple #2
0
def vector_apply(f, x, *arg):
    """
    apply **f** to array **x** with given arguments fast. This is a fast
    version of::

        np.array([f(xi,*arg) for xi in x ])

    useful when you try to plot something
    """
    return _vector_apply(f, x, arg)
Exemple #3
0
def fwhm_f(f, range, arg=None, bins=1000):

    arg=tuple() if arg is None else arg

    x = np.linspace(range[0], range[1], bins)
    y = _vector_apply(f, x, arg)
    imax = np.argmax(y)
    ymax = y[imax]
    rs = y[imax:]-ymax/2.0
    ls = y[:imax]-ymax/2.0
    xl = 0
    xr = 0

    il = first_neg(ls, 'l')
    #print il,x[il],ls[il],x[il+1],ls[il+1]
    xl = xintercept(x[il], ls[il], x[il+1], ls[il+1])

    ir = first_neg(rs, 'r')
    #print ir,x[imax+ir],rs[ir],x[ir+1],rs[ir+1]
    xr = xintercept(x[imax+ir], rs[ir], x[imax+ir-1], rs[ir-1])

    return (xl, xr)