Hello dear numpy community.

I would like to propose an enhancement to the 
numpy.lib.recfunctions.structured_to_unstructured() function. I have submitted 
a PR already: <https://github.com/numpy/numpy/pull/23652>
The PR also contains a short example.

The structured_to_unstructured() function already returns views, if all 
elements in the structured array have the same dtype (or have sub-arrays of the 
same dtype) and are contiguous.
I propose to relax the requirement of being contiguous, and instead only 
require that the offset between the fields is constant (so that it can be 
turned into a stride).

This will for example allow performing structured_to_unstructured when 
selecting a subset of fields, e.g. from a vertex containing x, y, z, red, 
green, and blue (which would formerly return a copy):
`structured_to_unstructured(vertex[['x', 'y', 'z']])`


Additional changes:
a) For views, ndarray (not an array subclass) is always returned: 
structured_to_unstructured() adds a new dimension to the array, but some 
subclasses behave strangely if that is done. For example, the numpy.matrix 
class always tries to keep 2 dimensions, which causes issues here.
Maybe we want to change structured_to_unstructured() to always return an 
ndarray, even in the case of a copy? So far, the documentation does not specify 
if subclasses are preserved.
b) The `base` attribute of the array will be more deeply nested than before. 
The only way I can think of to work around this, is to use the 
__array_interface__ directly.
_______________________________________________
NumPy-Discussion mailing list -- numpy-discussion@python.org
To unsubscribe send an email to numpy-discussion-le...@python.org
https://mail.python.org/mailman3/lists/numpy-discussion.python.org/
Member address: arch...@mail-archive.com

Reply via email to