[Numpy-discussion] Performance of defmatrix.py:103(__array_finalize__)

Travis Oliphant oliphant.travis at ieee.org
Wed Jul 19 11:46:20 EDT 2006


Kevin Jacobs <jacobs at bioinformed.com> wrote:
> Hi all,
>
> Is it expected that the following script would spend over half of the 
> total execution time in defmatrix.py:103(__array_finalize__)?
>
> from numpy import matrix
>
> m=matrix( (1,1) )
> for i in range(1000000):
>   m[0,0] = 0.
>
>
> Python version is 2.5b1, NumPy 0.9.8.
>
> More importantly, is there a way to avoid this overhead?
This over-head should be removed in latest SVN NumPy.  Basically, at 
each point in the loop the 0. is being converted to a matrix.  You could 
probably avoid the over-head by doing the conversion first to a 0-d array.

val = array(0.)
m = matrix( (1,1) )
for i in range(10000):
     m[0,0] = val



-Travis





More information about the NumPy-Discussion mailing list