Paul McGuire wrote:
> "RonnyM" <[EMAIL PROTECTED]> wrote in message
> news:[EMAIL PROTECTED]
>
>>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
"RonnyM" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
> 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 rang
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]
"RonnyM" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
> 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 funct
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 *
"map" takes a function and a list, applies the function to each item in
a list, and returns the result list. For example:
>>> def f(x): return x + 4
>>> numbers = [4, 8, 15, 16, 23, 42]
>>> map(f, numbers)
[8, 12, 19, 20, 27, 46]
So, rather that ask if there is a different way to write f, I'd j
Ronny Mandal wrote:
> Assume you have a mathematical function, e.g. f(x) = x + 4
>
> To calculate all the values from 1 to n, a loop is one alternative.
>
Numeric and friends (numarray,numpy) have something like numarray.arange
- they return arrays similar to the lists returned by standard libs
Are you looking for the "map" function?
>>> def f(x): return x+4
>>> map(f, [1,2,3,3,70])
[5, 6, 7, 7, 74]
CyrilOn 2/28/06, Ronny Mandal <[EMAIL PROTECTED]> wrote:
Assume you have a mathematical function, e.g. f(x) = x + 4To calculate all the values from 1 to n, a loop is one alternative.But to m
Assume you have a mathematical function, e.g. f(x) = x + 4
To calculate all the values from 1 to n, a loop is one alternative.
But to make this function work with vectors instead i.e
f(x_vector) = result_vector,
how should the function then be implemented?
Thanks
RM
--
Support bacteria - it's