[SciPy-user] vectorize(function) did not return arrays?
Yichun Wei
yichunwe at usc.edu
Wed Jan 19 19:44:51 EST 2005
Dear Experts,
1) I suppose vectorize could return arrays, (I was evaluating a function
over a 2-d grid, and each function call should return an array at every
point in this grid as a result. I would like to construct a 3-d array
with these results.)
def helper(x,y):
return myconvolve (a[x,y], k[x,y]) [NewAxis,NewAxis,:]
vec_helper = vectorize(helper)
x, y = ogrid[ 0:16, 0:16 ]
lres = zeros((16,16),'O')
lres = vec_helper(x,y)
I read through the previous posts on this list by Travis,
http://mail.python.org/pipermail/python-list/1999-June/004440.html
Also I find on Travis's pylab pages:
"There is also a class that allows wrapping an arbitrary Python function
with scalar inputs or outpus so that the wrapped function behaves like a
ufunc (taking array arguments and returning array array arguments". Thus
I supposed this should be a mature feature in Scipy. However I could not
get results as expected. Did I do anything wrong here.
Also,
2) The code
lres = zeros((16,16),'O')
lres = vec_helper(x,y)
does not work either. Long ago (also in 1999), there was someone
complaining about this:
http://mail.python.org/pipermail/python-list/1999-June/004440.html
But there was no concrete anwser to this. The work-around does not work
for me. I suppose there should be some better way to do this otherwise
people won't stop talking about this issue... I dug a little via google
but it could not tell me more on this...
Do you have any suggestion? Thanks in advance!
- yichun
More information about the SciPy-User
mailing list