Re: Vectorization

2006-06-06 Thread Robert Kern
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

Re: Vectorization

2006-06-06 Thread Paul McGuire
"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

Re: Vectorization and Numeric (Newbie)

2006-02-28 Thread johnzenger
"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

Re: Vectorization and Numeric (Newbie)

2006-02-28 Thread Juho Schultz
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

Re: Vectorization and Numeric (Newbie)

2006-02-28 Thread Cyril Bazin
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