[Numpy-discussion] field names on numpy arrays
Fernando Perez
fperez.net@gmail....
Thu Jun 4 14:12:40 CDT 2009
Howdy,
2009/6/3 Stéfan van der Walt <stefan@sun.ac.za>:
>> however i seem to lose simple operations such as multiplication (a_array*2)
>> or powers (a_array**2).
>
> As a workaround, you can have two views on your data:
I was thinking about this yesterday, because I'm dealing with exactly
this same problem in a local project. How hard would it be to allow
structured arrays to support ufuncs/arithmetic for the case where
their dtype is actually a composite of the same 'native' ones?
Basically, for cases where one could manually make a flattened view
using the 'base' dtype, do the operation, and repack the output into
the structured dtype, perhaps numpy could support it natively?
I can see there being a small cost to this, but the check could be
very fast, because the information on whether a given dtype is in fact
a composite of identical native ones or not can be stored statically,
at construction time, in the dtype object itself. That way, at
runtime, the ufunc/arithmetic machinery only needs to check this
static flag, and if it's true, it can take the (slightly slower) path
of (flatten,operate,repack) instead of bailing out with an error as it
does today.
It seems to me that this would make structured arrays even more useful
and powerful than they already are, at minimal performance cost (and
without knowing for sure, my intuition tells me that the
implementation isn't all that bad, though I could be wrong).
Cheers,
f
More information about the Numpy-discussion
mailing list