[Numpy-discussion] how can we concatenate structured arrays ?

Skipper Seabold jsseabold@gmail....
Wed Sep 16 08:58:12 CDT 2009

On Wed, Sep 16, 2009 at 5:10 AM,  <josef.pktd@gmail.com> wrote:
> On Wed, Sep 16, 2009 at 4:42 AM, Pierre GM <pgmdevlist@gmail.com> wrote:
>> On Sep 16, 2009, at 4:25 AM, josef.pktd@gmail.com wrote:
>>> I have two structured arrays of different types. How can I
>>> horizontally concatenate the two arrays? Is there a direct way, or do
>>> I need to start from scratch?
>> Check numpy.lib.recfunctions, that should get you started.
> Thanks, I was doing that, but without reading through every option
> of every function, they all seem to do something more
> complicated, like merge or joinby,
> append_fields doesn't look very convenient, adds one by one
> looking some more recursive_fill_fields seems also to do the
> loop (but also handles nested structured arrays)
> tt = np.empty((10,1),dt2)
> numpy.lib.recfunctions.recursive_fill_fields(testdata, tt)
> numpy.lib.recfunctions.recursive_fill_fields(testdatacont, tt)
> So, I guess the answer is, loop over columns of structured arrays
> Josef

I spent a lot of time trying to do this for categorical in statsmodels
when we have to append the array of dummies to a mixed dtype
structured array.

recfunctions.append_fields was the best I could come up with.


More information about the NumPy-Discussion mailing list