Created
April 29, 2012 19:32
-
-
Save astrofrog/2552867 to your computer and use it in GitHub Desktop.
Merge Numpy structured arrays
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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