Hi, I was wondering if there was any way to speed up the following code:
y = N.zeros((n, K)) for i in range(K): y[:, i] = gauss_den(data, mu[i, :], va[i, :]) Where K is of order 1e1, n of order 1e5. Normally, gauss_den is a quite expensive function, but the profiler tells me that the indexing y[:,i] takes almost as much time as the gauss_den computation (which computes n exp !). To see if the profiler is "right", i replaces with the (non valid) following function: y = N.zeros((n, K)) for i in range(K): yt = gauss_den(data, mu[i, :], va[i, :]) return y Where more than 99% of the code is spent inside gauss_den. I guess the problem is coming from the fact that y being C order, y[:, i] needs accessing data in a non 'linear' way. Is there a way to speed this up ? I did something like this: y = N.zeros((K, n)) for i in range(K): y[i] = gauss_den(data, mu[i, :], va[i, :]) return y.T which works, but I don't like it very much. Isn't there any other way ? David ------------------------------------------------------------------------- Take Surveys. Earn Cash. Influence the Future of IT Join SourceForge.net's Techsay panel and you'll get the chance to share your opinions on IT & business topics through brief surveys -- and earn cash http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV _______________________________________________ Numpy-discussion mailing list Numpy-discussion@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/numpy-discussion