Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Combining two record arrays

I have two Numpy record arrays that have exactly the same fields. What is the easiest way to combine them into one (i.e. append one table on to the other)?

like image 950
astrofrog Avatar asked Sep 10 '26 02:09

astrofrog


1 Answers

Use numpy.hstack():

>>> import numpy
>>> desc = {'names': ('gender','age','weight'), 'formats': ('S1', 'f4', 'f4')} 
>>> a = numpy.array([('M',64.0,75.0),('F',25.0,60.0)], dtype=desc)
>>> numpy.hstack((a,a))
array([('M', 64.0, 75.0), ('F', 25.0, 60.0), ('M', 64.0, 75.0),
       ('F', 25.0, 60.0)], 
      dtype=[('gender', '|S1'), ('age', '<f4'), ('weight', '<f4')])
like image 94
rcs Avatar answered Sep 11 '26 15:09

rcs



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!