[Numpy-discussion] frompyfunc question

Larsen, Brian A balarsen at lanl.gov
Wed Jun 20 16:32:14 EDT 2012


Hello all,

I was looking to wrap hasattr in a numpy ufunc and got some weird behavior.

Here is a transcript:
In [5]: import numpy as np
In [6]: np.__version__
Out[6]: '1.6.2'
In [7]: b = [1,2,3]
In [7]: nphas = np.frompyfunc(hasattr, 2, 1)
In [8]: hasattr(b, 'extend')
Out[8]: True
In [9]: nphas(b, 'extend')
Out[9]: NotImplemented
In [10]: nphas(b, ['extend']*2)
Out[10]: NotImplemented
In [11]: type(nphas(b, ['extend']*2))
Out[11]: NotImplementedType


This isn't an exception but an object returned, what what or why is not implemented?

What I really want to do is be able to run hasattr like isinstance is run, isinstance(b, (list, str))


Anyone have any thoughts/advice here?

Cheers,

Brian










--

Brian A. Larsen
ISR-1 Space Science and Applications
Los Alamos National Laboratory
PO Box 1663, MS-D466
Los Alamos, NM 87545
USA

(For overnight add:
SM-30, Bikini Atoll Road)

Phone: 505-665-7691
Fax:   505-665-7395
email: balarsen at lanl.gov<mailto:balarsen at lanl.gov>

Correspondence /
Technical data or Software Publicly Available



-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/numpy-discussion/attachments/20120620/26c22ea0/attachment.html>


More information about the NumPy-Discussion mailing list