Update An error has occurred in the script.
I am working on visualizing a set of Julia and Mandelbrot, as well as Newton fractals - for this I need to calculate many values ββin the complex plane. I can use any type of mathematical function that I want, but thatβs enough for polynomials.
I need to calculate the derivative and function / polynomial value, so I looked into the numpy module and found out about numpy.polyder() and numpy.polyval() . It was like what I needed, but suddenly my scripts became very slow.
I tried to come up with some simple test to show the time difference. For this, I wrote the following script:
import numpy as np import cmath import time from itertools import product C = 0.37 + 0.45j pol = [1,0,0] start_time = time.time() for i in xrange(100000): C = np.polyval(pol, C) print "Polyval: {}".format( time.time() - start_time ) print C C = 0.37 + 0.45j
Basically this script calculates a lot of values ββfor the polynomial g (C) = C ** 2. Results in time (actual program output):
Polyval: 2.34903216362 0j Standard: 0.0198249816895 0j
I would not put this test in the best way, having done something similar for the first time. But even if there was some kind of error, running my other scripts shows a big time difference.
Question
Is there any way to do this faster? I understand that calling another function takes a lot of time, but still. Should I rethink the advantage of being able to change polynomial coefficients in only one place versus lack of time? Any other suggestions on how to deal with such a problem?
source share