[SciPy-user] vectorizing a function inside a class
Matthieu Brucher
matthieu.brucher@gmail....
Tue Sep 4 03:43:36 CDT 2007
Hi,
Vectorize() vectorizes a function that takes one argument (or more)
arguments that are the values to be used. Then the vectorized function will
take the same number of arguments, this time it will be arrays.
For what you want to do, vectorize can't help you, it can't know that what
it has to do is to put the argument in self.x instead of passing the
argument.
Matthieu
2007/9/4, morovia morovia <jallikattu@googlemail.com>:
>
>
> Hello all,
>
> I am trying to vectorize a function which resides in the class.
> Can any one help me out ? I have appended the test code below.
>
> from scipy import vectorize
>
> ************************************************
> def square(x):
> return x.x
>
> v_sq = vectorize(square)
>
> result = v_sq(x)
>
> ************************************************
> Just new to class !!
>
> I just want to mimic the above function,
> which works. But, inside the class structure,
> it does not !
>
> from scipy import vectorize
>
> class a:
> def __init__(self,x):
> self.x = x
> def square(self):
> return self.x*self.x
> def v_sq(self):
> vect_sq = vectorize(square)
> return vect_sq(self)
>
> x = [1,2,3]
> fn = a(x)
> fn.v_sq()
>
>
> Thanks in advance,
> Morovia.
>
> _______________________________________________
> SciPy-user mailing list
> SciPy-user@scipy.org
> http://projects.scipy.org/mailman/listinfo/scipy-user
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://projects.scipy.org/pipermail/scipy-user/attachments/20070904/0ecdfe80/attachment.html
More information about the SciPy-user
mailing list