[Numpy-discussion] Create a numpy array from an array of a C structure

Charles R Harris charlesr.harris@gmail....
Mon Mar 10 00:54:34 CDT 2008


On Sun, Mar 9, 2008 at 2:57 AM, mani sabri <mani.sabri@gmail.com> wrote:

> Hello
>
> Is it possible to create a numpy array from an array of a C structure like
> this?
>
> struct RateInfo
>  {
>   unsigned int      ctm;
>   double            open;
>   double            low;
>   double            high;
>   double            close;
>   double            vol;
>  };


You might have an alignment problem if unsigned int is of different size
than double and depending on the architecture and whether or not the OS is
64 bit. C compilers like to add spaces so that each variable is efficiently
aligned and as a result C structures tend to be non-portable and should be
avoided for data storage and transport. It helps a bit if you place the
longest variables first in the structure but there are no guarantees. You
should at least check the size of the structure to see if it is packed or
not.

Chuck
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://projects.scipy.org/pipermail/numpy-discussion/attachments/20080309/3ebc5ff1/attachment.html 


More information about the Numpy-discussion mailing list