[PYTHON MATRIX-SIG] Applying a general function to an array
David Redish
dredish@CS.cmu.edu
Thu, 22 Feb 1996 13:02:50 -0500
>An example of the sort of function you want to do this with would be
>very helpful in answering this. Many python functions already work as
>you describe.
This is fine for already-coded python functions (like exp), but what I
really want to know how to add new C-coded functions.
For example, I have a gaussian function coded up in C that takes care
of normalization, random-sampling with a gaussian distribution, etc.
So I'd like to be able to apply that function to each element of an
array. I could recode the function in python, but that would be much
slower. Also, it's already nicely coded-up as a C-coded python object
and software-reuse is the word here, right?
e.g. I can currently do:
x = 10
G = Gaussian(wt, mean, variance)
y = G(x)
A = arange(10)
G = Gaussian(wt, mean, variance)
Y = G(A)
where G is a C-coded python object that defines a __call__ function.
thanx
adr
PS. I am using these for NN's similar to RBFs. (:
------------------------------------------------------------
David Redish Computer Science Department CMU
graduate student Neural Processes in Cognition Training Program
Center for the Neural Basis of Cognition (CNBC)
http://www.cs.cmu.edu/Web/People/dredish/home.html
------------------------------------------------------------
maintainer, CNBC website:
http://www.cs.cmu.edu/Web/Groups/CNBC
maintainer, Cog-Neuro Sites on the Internet, courtesy CNBC:
http://www.cs.cmu.edu/Web/Groups/CNBC/other
maintainer, NIPS*96 website:
http://www.cs.cmu.edu/Web/Groups/NIPS
------------------------------------------------------------
=================
MATRIX-SIG - SIG on Matrix Math for Python
send messages to: matrix-sig@python.org
administrivia to: matrix-sig-request@python.org
=================