Skip to content

Instantly share code, notes, and snippets.

@astrofrog
Created April 29, 2012 19:32
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save astrofrog/2552867 to your computer and use it in GitHub Desktop.
Save astrofrog/2552867 to your computer and use it in GitHub Desktop.
Merge Numpy structured arrays
import numpy as np
def merge_structured_arrays(array1, array2):
n1 = len(array1)
n2 = len(array2)
array_out = array1.copy()
array_out.resize(n1 + n2)
array_out[n1:] = array2
return array_out
a = np.array(zip([1,2,3],['a','b','c']), dtype=[('col1', int), ('col2', 'S1')])
b = np.array(zip([4,5,6],['d','e','f']), dtype=[('col1', int), ('col2', 'S1')])
c = merge_structured_arrays(a, b)
print c['col1']
print c['col2']
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment