[Numpy-discussion] Serializing numpy record array

Robert Kern robert.kern at gmail.com
Sun Jun 13 21:04:11 EDT 2010


On Sun, Jun 13, 2010 at 19:52, Vishal Rana <ranavishal at gmail.com> wrote:
> I created a record array (from strings and floats) with no dtype defined as:
> ra = np.core.records.fromrecords(sq_list, names=("a", "b", "c"))
> ra.a is found to be of type numpy.float64, when I serialize it using pyamf
> under Mac OS X it works great but under ubuntu 10.04 it fails. Looks like
> serialization is failing for type numpy.float64.

Please don't just say that something fails. Show us exactly what you
did (copy-and-paste a minimal, but complete example of the code that
fails) and show us exactly what errors you get (copy-and-paste the
tracebacks).

Since I'm sure most of us here aren't familiar with the details of
PyAMF, perhaps you can read its documentation or its code to determine
exactly how it is trying to serialize objects and tell us that. Is it
using pickle? Is it using its own scheme?

> Is the any work around, I
> was trying to set dtype=object is that ok?

Probably not what you want.

> Also how can I set same dtype (for eg. object) for all a, b, and c?

In [3]: x = np.rec.fromrecords([('string', 10, 15.5)], names=['a', 'b', 'c'])

In [4]: x
Out[4]:
rec.array([('string', 10, 15.5)],
      dtype=[('a', '|S6'), ('b', '<i4'), ('c', '<f8')])

In [5]: x.astype(np.dtype([('a', object), ('b', object), ('c', object)]))
Out[5]:
rec.array([('string', 10, 15.5)],
      dtype=[('a', '|O4'), ('b', '|O4'), ('c', '|O4')])

-- 
Robert Kern

"I have come to believe that the whole world is an enigma, a harmless
enigma that is made terrible by our own mad attempt to interpret it as
though it had an underlying truth."
  -- Umberto Eco



More information about the NumPy-Discussion mailing list