[Numpy-discussion] np.void from 0d array + subclassing

David Goldsmith d.l.goldsmith at gmail.com
Thu Dec 17 13:36:50 EST 2009


On Thu, Dec 17, 2009 at 6:16 AM, Pierre GM <pgmdevlist at gmail.com> wrote:
> All,
> * What is the most efficient way to get a np.void object from a 0d structured ndarray ?
> * Is there any way to subclass np.void ?

The standard way (more or less) works for me:

>>> class myvoidclass(np.void):
...     pass
...
>>> foo = myvoidclass()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: function takes exactly 1 argument (0 given)
>>> foo = myvoidclass(1)
>>> dir(foo)
['T', '__abs__', '__add__', '__and__', '__array__',
'__array_interface__', '__array_priority__', '__array_struct__', '__
array_wrap__', '__class__', '__copy__', '__deepcopy__', '__delattr__',
'__delitem__', '__dict__', '__div__', '__divmod__
', '__doc__', '__eq__', '__float__', '__floordiv__', '__ge__',
'__getattribute__', '__getitem__', '__gt__', '__hash__',
'__hex__', '__init__', '__int__', '__invert__', '__le__', '__len__',
'__long__', '__lshift__', '__lt__', '__mod__', '__m
odule__', '__mul__', '__ne__', '__neg__', '__new__', '__nonzero__',
'__oct__', '__or__', '__pos__', '__pow__', '__radd__
', '__rand__', '__rdiv__', '__rdivmod__', '__reduce__',
'__reduce_ex__', '__repr__', '__rfloordiv__', '__rlshift__', '__
rmod__', '__rmul__', '__ror__', '__rpow__', '__rrshift__',
'__rshift__', '__rsub__', '__rtruediv__', '__rxor__', '__seta
ttr__', '__setitem__', '__setstate__', '__str__', '__sub__',
'__truediv__', '__weakref__', '__xor__', 'all', 'any', 'arg
max', 'argmin', 'argsort', 'astype', 'base', 'byteswap', 'choose',
'clip', 'compress', 'conj', 'conjugate', 'copy', 'cum
prod', 'cumsum', 'data', 'diagonal', 'dtype', 'dump', 'dumps', 'fill',
'flags', 'flat', 'flatten', 'getfield', 'imag', '
item', 'itemset', 'itemsize', 'max', 'mean', 'min', 'nbytes', 'ndim',
'newbyteorder', 'nonzero', 'prod', 'ptp', 'put', '
ravel', 'real', 'repeat', 'reshape', 'resize', 'round',
'searchsorted', 'setfield', 'setflags', 'shape', 'size', 'sort',
 'squeeze', 'std', 'strides', 'sum', 'swapaxes', 'take', 'tofile',
'tolist', 'tostring', 'trace', 'transpose', 'var', 'v
iew']

Is there something more specific you want to do?

DG

> Thanks a lot in advance !
> P.
> _______________________________________________
> NumPy-Discussion mailing list
> NumPy-Discussion at scipy.org
> http://mail.scipy.org/mailman/listinfo/numpy-discussion
>



More information about the NumPy-Discussion mailing list