hi robert,

> I had a way of doing it that would be really robust, but really slow.
> Expand each of the factorials on the denominator and numerator separately
> and store as separate lists. Then remove all terms common to both lists and
> multiply the results. However, this heavily uses append and would be too
> slow for large value of N.
>

another exact solution would be to do an accumulator trick (treating every
factorial as a factor):

def run_accumulate(all_factors):
    a = np.zeros((all_factors.max()+1))
    b = np.arange(all_factors.max()+1)
    for factor in all_factors:
        a[:(abs(factor)+1)] += np.sign(factor)
    return np.exp(np.dot(a[2:], np.log(b[2:])))

seems to run pretty quickly

%timeit run_accumulate(np.array([50, 10, -30, -20])) # numerator factors are
+ve, denominator is -ve

10000 loops, best of 3: 98.3 us per loop

 cheers,

satra
------------------------------------------------------------------------------
The demand for IT networking professionals continues to grow, and the
demand for specialized networking skills is growing even more rapidly.
Take a complimentary Learning@Cisco Self-Assessment and learn 
about Cisco certifications, training, and career opportunities. 
http://p.sf.net/sfu/cisco-dev2dev
_______________________________________________
Scikit-learn-general mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/scikit-learn-general

Reply via email to