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

Pierre GM pgmdevlist at gmail.com
Thu Dec 17 17:11:03 EST 2009


On Dec 17, 2009, at 10:16 AM, Francesc Alted wrote:
> A Thursday 17 December 2009 15:16:29 Pierre GM escrigué:
>> All,
>> * What is the most efficient way to get a np.void object from a 0d
>> structured ndarray ?
> 
> I normally use `PyArray_GETITEM` C macro for general n-d structured arrays.  I 
> suppose that this will work with 0-d arrays too.

Francesc, you're overestimating my knowledge of C... Can we stick to the Python implementation ?
Here's the catch: IIUC, each individual element of a nD structured array is a void, provided the element can be accessed, ie that n>0. A 0D array cannot be indexed, so I don't know how capture the object below. The sad trick I found was to do a .reshape(1)[0], but that looks really overkill...

> 
> The standard way (more or less) works for me:
> 
>>>> class myvoidclass(np.void):
> ...     pass
> ...

David, what do you do w/ the __new__ of myvoidclass ? Just an empty class doesn't help me much, 'm'fraid.




More information about the NumPy-Discussion mailing list