Re: Need help vectorizing code

2014-01-19 Thread Oscar Benjamin
On 18 January 2014 20:51, Kevin K wrote: > I have some code that I need help vectorizing. > I want to convert the following to vector form, how can I? I want to get rid > of the inner loop - apparently, it's possible to do so. > X is an NxD matrix. y is a 1xD vector. > > def foo(X, y, mylambda, N

Re: Need help vectorizing code

2014-01-18 Thread Peter Otten
Kevin K wrote: > I have some code that I need help vectorizing. > I want to convert the following to vector form, how can I? I want to get > rid of the inner loop - apparently, it's possible to do so. X is an NxD > matrix. y is a 1xD vector. > > def foo(X, y, mylambda, N, D, epsilon): > ... >

Re: Need help vectorizing code

2014-01-18 Thread Kevin K
I didn't paste the whole function, note the ... before and after. I do use the values. I want to get rid of one of the loops so that the computation becomes O(D). Assume vectors a and c should get populated during the compute, each being 1xD. Thanks On Saturday, January 18, 2014 12:51:25 PM U

Re: Need help vectorizing code

2014-01-18 Thread Joshua Landau
On 18 January 2014 20:51, Kevin K wrote: > def foo(X, y, mylambda, N, D, epsilon): > ... > for j in xrange(D): > aj = 0 > cj = 0 > for i in xrange(N): > aj += 2 * (X[i,j] ** 2) > cj += 2 * (X[i,j] * (y[i] - w.transpose()*X

Need help vectorizing code

2014-01-18 Thread Kevin K
I have some code that I need help vectorizing. I want to convert the following to vector form, how can I? I want to get rid of the inner loop - apparently, it's possible to do so. X is an NxD matrix. y is a 1xD vector. def foo(X, y, mylambda, N, D, epsilon): ... for j in xrange(D):