why scipy cause my program slow?

robert no-spam at no-spam-no-spam.invalid
Tue Jan 16 07:06:03 EST 2007


HYRY wrote:
> Thanks, by your hint, I change type(data) to type(data[0]), and I get
> <type 'float'>
> <type 'numpy.float64'>
> So, calculate with float is about 5x faster numpy.float64.
> 

approx..
numpy funcs all upcast int to int32 and float to float32 and 
int32/float to float32 etc. This is probably ill behavior.
float32 arrays should only arise if numpy.array(l,dtype=numpy.float32)

In your example you'll best go to numpy/scipy types very early 
(not mixing with the python array type in addition) and do the 
array computations with scipy

left = [abs(x-mean) for x in left]

->

data = scipy.array(f.readframes(t[3]),"h")
..
left = abs(left-mean)

code the test(data) similar - see also scipy.signal.lfilter etc.

and cast types down to Python types late like float(mynumfloat) ...


The type magic and speed loss will and pickle problems will 
probably only disapear, when float & int are handled as extra 
(more conservative) types in numpy - with numpy scalar types only 
on request. Currently numpy uses Python.


Robert



More information about the Python-list mailing list