[Numpy-discussion] combining recarrays

ctw lists.20.chth@xoxy....
Tue Dec 30 12:10:33 CST 2008


I'm a bit stumped by the following: suppose I have several recarrays
with identical dtypes (identical field names, etc.) and would like to
combine them into one rec array, what would be the best way to do
that? I tried using np.rec.fromrecords, but that doesn't produce the
desired result. As a minimal example consider the following code:

desc = np.dtype({'names':['a','b'],'formats':[np.float,np.int]})
rec1 = np.zeros(3,desc)
rec2 = np.zeros(3,desc)

Now I have two recarrays of shape (3,) that both look like this:
array([(0.0, 0), (0.0, 0), (0.0, 0)],
      dtype=[('a', '<f8'), ('b', '<i4')])

I would like to turn them into one new recarray of shape (6,) that
looks like this:
array([(0.0, 0), (0.0, 0), (0.0, 0), (0.0, 0), (0.0, 0), (0.0, 0)],
      dtype=[('a', '<f8'), ('b', '<i4')])

Any ideas?

More information about the Numpy-discussion mailing list