[Numpy-discussion] vectorize problem

Steffen Loeck steffen.loeck at gmx.de
Tue Apr 25 04:25:22 CDT 2006


Hello all,

I have a problem using scalar variables in a vectorized function:

from numpy import vectorize

def f(x):
    if x>0: return 1
    else: return 0

F = vectorize(f)

F(1)

gives the error message:
---------------------------------------------------------------------------
exceptions.AttributeError     Traceback (most recent call last)

.../function_base.py in __call__(self, *args)
    619
    620         if self.nout == 1:
--> 621             return self.ufunc(*args).astype(self.otypes[0])
    622         else:
    623             return tuple([x.astype(c) for x, c in 
zip(self.ufunc(*args), self.otypes)])

AttributeError: 'int' object has no attribute 'astype'

Is there any way to get vectorized functions working with scalars again?

Regards
Steffen




More information about the Numpy-discussion mailing list