[SciPy-user] Re: vectorize(function)/arraymap did not return arrays?
Yichun Wei
yichunwe at usc.edu
Tue Jan 25 23:38:12 EST 2005
Hi Expects,
Sorry if I changed what I've said. The list comprehension could not work
as fast as I expected... it does look like syntaxic suger when I use it
in my application. This is my problem: basically what I need to do is,
res = [convolve1d(a[x,y], k[x,y]) for x in range(16) for y in range(16)]
res = sum(res)
k.shape is (16,16,40), a.shape is (16,16,1800) or so. So the result will
be a 1-d array of length 1839.
I had to do this quickly for it will be repeated for more than 10000
times in optimization. I implemented this in matlab and find it runs
fairly quick (conv in matlab is really quick. And I think matlab has
been optimized for for-loops.)
After playing with convolution of scipy and for loops for several days,
I realized that I have to write some C++ code to accomplish this in
python without a prominent performance headache. However, if I want to
implement the whole nested loops in C++ using weave.inline, I have to
throw out all the numeric vectorized syntax and rewrite the convolve1d
function again in C++ (don't I? Would CXX helps some with this problem?
I had to admit that I am reluctant to code in C++). Also all the
materials I read suggest avoiding calling back python functions in weave.
Could you share some opinion on this? Thanks in advance.
- yichun
Yichun Wei wrote:
>
> Well, I found list comprehension is actually fast enough.
>
> res = [myconvolve(a[x,y], k[x,y]) for x in range(16) for y in range(16)]
>
> which is much faster than
>
> for x in range(16):
> for y in range(16):
> .....
>
> This thread says that list comprehension could be comparable to map, or
> even better if taking in to consideration the time calling helper
> functions in map:
> http://mail.python.org/pipermail/python-list/2005-January/259690.html
>
> I did not try list comprehension earlier because I roughly remember I
> was told that list comprehension is syntaxic suger of for loops...
>
>
More information about the SciPy-User
mailing list