Vectorization

2006-06-06 Thread RonnyM
Hi!

Need to vectorize this, but do not have a clue.

a = n*m matrix
x and y are n and m vectors

Suggestions?



def fill(a, x, y):
for i in range(1,a.shape[0]):
xp = x[i]
for j in range(a.shape[1]):
yp = y[j]
a[i,j] = sin(xp*yp)*exp(-xp*yp) + a[i-1,j]
return a

Thanks in advance,

Ronny Mandal

-- 
http://mail.python.org/mailman/listinfo/python-list


Numeric, vectorization

2006-05-01 Thread RonnyM
Hello.

I want to vectorize this operation, which below is implemented as a
for-loop:

def smoothing_loop( y ): #y is an array with noisy values
ybar = []
ybar.append( y[0] )
#Smoothing with a loop
length = size( y )
for i in range( 1, length -1 ):
ybar.append( .5 * ( y[ i-1 ] + y[ i + 1 ] ) )

e.g. y = [ 1, 2, 3, 4, 5, 6 ,7 ,8, 9 ]

ybar = [ 1, (1 + 3)*.5,(2 + 4)*.5,(3 + 5)*.5,..., (n-1 + n+1)*.5 ], n =
1,...len(y) -1

How do I make a vectorized version of this, I will prefer not to
utilize Map or similar functions, but numeric instead.


Regards,

Ronny Mandal

-- 
http://mail.python.org/mailman/listinfo/python-list