[Numpy-discussion] dumb structured arrays question
David Warde-Farley
dwf at cs.toronto.edu
Thu Sep 17 18:12:01 EDT 2009
If I have a 1-dimensional array with a structured dtype, say str,
float, float, float, float.... where all the float columns have their
own names, and I just want to extract all the floats in the order they
appear into a 2D matrix that disregards the dtype metadata... Is there
an easy way to do that?
Currently the only thing I can think of is
out = []
for name in arr.dtype.names:
if name != 'condition': # my single str field
out.append(arr['name'])
out = np.array(out)
Is there already some convenience function for this, to coerce numeric
compound dtypes into an extra dimension?
It seems conceivable that I might be able to pull some dirty trick
with stride_tricks that would even allow me to avoid the copy, since
it'd just be a matter of an extra few bytes on the 2nd dimension
stride to skip over the string data.
Thanks,
David
More information about the NumPy-Discussion
mailing list