diff options
author | Travis Oliphant <oliphant@enthought.com> | 2006-04-26 17:11:27 +0000 |
---|---|---|
committer | Travis Oliphant <oliphant@enthought.com> | 2006-04-26 17:11:27 +0000 |
commit | e328ecf10f570df8900438ec9e727b3af68c7f84 (patch) | |
tree | 4e7fe5a41ee915e2a468dab3c56cfb6785b5d280 /numpy/lib | |
parent | d2dfaf23b530b7f932e225fba71ca0194258864a (diff) | |
download | numpy-e328ecf10f570df8900438ec9e727b3af68c7f84.tar.gz |
Fix vectorize to handle scalar return values.
Diffstat (limited to 'numpy/lib')
-rw-r--r-- | numpy/lib/function_base.py | 15 |
1 files changed, 13 insertions, 2 deletions
diff --git a/numpy/lib/function_base.py b/numpy/lib/function_base.py index 03ac68ab1..2b7041422 100644 --- a/numpy/lib/function_base.py +++ b/numpy/lib/function_base.py @@ -616,9 +616,20 @@ class vectorize(object): self.lastcallargs = nargs if self.nout == 1: - return self.ufunc(*args).astype(self.otypes[0]) + ret = self.ufunc(*args) + c = self.otypes[0] + try: + return ret.astype(c) + except AttributeError: # scalar-case + return array(ret).astype(c) else: - return tuple([x.astype(c) for x, c in zip(self.ufunc(*args), self.otypes)]) + ret = [] + for x, c in zip(self.ufunc(*args), self.otypes): + try: + ret.append(x.astype(c)) + except AttributeError: + ret.append(array(x).astype(c)) + return tuple(ret) def cov(m,y=None, rowvar=1, bias=0): """Estimate the covariance matrix. |