[Numpy-discussion] Array dtype problems

Andrew Collette h5py@alfven....
Wed Feb 4 15:22:38 CST 2009


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?

Andrew Collette

More information about the Numpy-discussion mailing list