[SciPy-user] vectorizing a function inside a class

tjerk heijboer tjerk.heijboer@unibas...
Tue Sep 4 00:51:49 CDT 2007


use vectorize(self.square) ?

cheers

tjerk

On 04 Sep 2007, at 07:46, morovia morovia wrote:

>
> 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



More information about the SciPy-user mailing list