[Numpy-discussion] Array dtype problems

Andrew Collette h5py at alfven.org
Wed Feb 4 16:22:38 EST 2009


Hello,

I'm having an issue with 'array' dtypes; if I do this:

mydtype = numpy.dtype(('i', (4,)))
arr = numpy.empty((100,), dtype=mydtype)

then the array datatype shape is "absorbed" into the shape of the
array.  This simplifies indexing, but is really annoying as it means
that the dtype doesn't "round trip"; I can't even use use astype as it
complains about a shape mismatch.  How can I create an array in a
manner that preserves the dtype array information?  Or is there a way
to take an existing array of the correct shape and "re-cast" it to use
an array dtype?

Thanks,
Andrew Collette



More information about the NumPy-Discussion mailing list