Quoting from numdoc.pdf, dated March 31, 2001, in section "Creating an array from a function: fromfunction()"
The implementation of fromfunction consists of:
def fromfunction(function, dimensions): return apply(function, tuple(indices(dimensions)))
which means that the function function is called for each element in the sequence indices(dimensions) [...]
This is wholly incorrect. apply() does not call a function for each element in the sequence, apply calls a function exactly *once*, using the elements of the sequence for arguments.
Also, that same section of the documentation refers to "the first example below [...] works" and "the second array [...] fails", but there is only one example, which apparently is the failing one (as it's named "buggy"). Having a *working* example would be nice. =)
Perhaps this is a formatting glitch in the documentation processor, but I couldn't find the documentation's source format.
and then... there's always the possibility that I'm barking up the wrong tree. What I'm trying to achieve is this: I've got a function which, given a vector describing a point in ndimensional space, returns a value for that point. I want a matrix of the shape I specify, filled these values, with the array indicies as coordinates for the points.
Is that too much to ask? ;)
Thanks,
 Kevin Turner
[using Python version 2.0, PyNum 19.0.0]
On Sun, May 27, 2001 at 09:28:08PM 0700, Kevin Turner wrote:
and then... there's always the possibility that I'm barking up the wrong tree. What I'm trying to achieve is this: I've got a function which, given a vector describing a point in ndimensional space, returns a value for that point. I want a matrix of the shape I specify, filled these values, with the array indicies as coordinates for the points.
err, I meant "multiarray", not "matrix"
Is that too much to ask? ;)
Thanks,
A previous report of this doc error had caused me to fix it in my copy but it hadn't made it up to the web yet. The section has been redone to make it clearer, I hope.
I am in the process of doing the update now.
The documentation source is not available to you.
Conventional use of fromfunction is like this:
from Numeric import * def f (x, y):
return x**2 + y**2
a=fromfunction(f, (3,2)) a
array([[0, 1], [1, 2], [4, 5]])
For your use, you need a "helper" function. Suppose g is your function.
def g(x):
return x[0] + x[1]**2
def helper (x, y):
return g([x,y])
from Numeric import * a = fromfunction(helper, (3,3)) a
array([[0, 1, 4], [1, 2, 5], [2, 3, 6]])
Of course, you can use a lambda to avoid explicity creating the helper.
fromfunction(lambda x,y:g([x,y]), (3,3))
array([[0, 1, 4], [1, 2, 5], [2, 3, 6]])
Original Message From: numpydiscussionadmin@lists.sourceforge.net [mailto:numpydiscussionadmin@lists.sourceforge.net]On Behalf Of Kevin Turner Sent: Sunday, May 27, 2001 9:28 PM To: numpydiscussion@lists.sourceforge.net Subject: [Numpydiscussion] fromfunction documentation
Quoting from numdoc.pdf, dated March 31, 2001, in section "Creating an array from a function: fromfunction()"
The implementation of fromfunction consists of:
def fromfunction(function, dimensions): return apply(function, tuple(indices(dimensions)))
which means that the function function is called for each element in the sequence indices(dimensions) [...]
This is wholly incorrect. apply() does not call a function for each element in the sequence, apply calls a function exactly *once*, using the elements of the sequence for arguments.
Also, that same section of the documentation refers to "the first example below [...] works" and "the second array [...] fails", but there is only one example, which apparently is the failing one (as it's named "buggy"). Having a *working* example would be nice. =)
Perhaps this is a formatting glitch in the documentation processor, but I couldn't find the documentation's source format.
and then... there's always the possibility that I'm barking up the wrong tree. What I'm trying to achieve is this: I've got a function which, given a vector describing a point in ndimensional space, returns a value for that point. I want a matrix of the shape I specify, filled these values, with the array indicies as coordinates for the points.
Is that too much to ask? ;)
Thanks,
 Kevin Turner
[using Python version 2.0, PyNum 19.0.0]
 Kevin Turner acapnotic@users.sf.net  OpenPGP encryption welcome here http://www.purl.org/wiki/python/KevinTurner
_______________________________________________ Numpydiscussion mailing list Numpydiscussion@lists.sourceforge.net http://lists.sourceforge.net/lists/listinfo/numpydiscussion
participants (2)

Kevin Turner

Paul F. Dubois