[Numpy-discussion] Numpy structures

Bob Cowdery bob at bobcowdery.plus.com
Fri Jun 8 06:31:19 EDT 2012

Hi all,

I am reading a datagram which contains within it a type. The type
dictates the structure of the datagram. I want to put this into a numpy
structure, one of which is:

As I don't know what I'm getting until I've read it (it seems I have to
read the whole datagram in one read) I don't know the shape of the
structure to use.

I have tried reading into:
np.zeros(1032, dtype='uint8')

and then attempting to copy to the correct structure. How should I do
this copy as numpy.copy() does not seem to work as if I then try to read
some fields in the structure it complains the fields don't exist.

Is there a better way to do this kind of thing, preferably without
causing a data copy?


More information about the NumPy-Discussion mailing list