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

Pierre GM pgmdevlist@gmail....
Thu Dec 17 17:41:37 CST 2009

On Dec 17, 2009, at 6:35 PM, Robert Kern wrote:
> On Thu, Dec 17, 2009 at 16:11, Pierre GM <pgmdevlist@gmail.com> wrote:
>> 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...
> a[()]

Well, that's slick and really neat !!! Typically Robert K's... Thanks a lot !!!
And would you have anything as cool for the reverse operation (from np.void to 0d array) ?

More information about the NumPy-Discussion mailing list