Vectorization
Robert Kern
robert.kern at gmail.com
Tue Jun 6 11:31:44 EDT 2006
Paul McGuire wrote:
> "RonnyM" <ronnyma at math.uio.no> wrote in message
> news:1149595753.611358.189070 at i39g2000cwa.googlegroups.com...
>
>>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
>
> Something like this, but the first row in a is never modified, is this
> correct?
>
> Note: this is a brute force Python attempt at a matrix, using a list of
> lists. Look also at the array and numarray modules.
The array module doesn't do matrices, and numarray is deprecated. Please point
new users to numpy, instead.
http://numeric.scipy.org/
Since the OP seems to already be using one of Numeric/numarray/numpy, (given
"a.shape"), I would suggest that he ask the question on the appropriate mailing
list:
https://lists.sourceforge.net/lists/listinfo/numpy-discussion
I won't attempt an answer until the OP answers about the first row.
--
Robert Kern
"I have come to believe that the whole world is an enigma, a harmless enigma
that is made terrible by our own mad attempt to interpret it as though it had
an underlying truth."
-- Umberto Eco
More information about the Python-list
mailing list